首页 > 其他分享 >1142 Maximal Clique(附测试点1,3错误分析)

1142 Maximal Clique(附测试点1,3错误分析)

时间:2023-09-04 15:33:12浏览次数:43  
标签:1142 Maximal 测试点 int Clique vertices clique maximal Yes

题目:

clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more adjacent vertex. (Quoted from https://en.wikipedia.org/wiki/Clique_(graph_theory))

Now it is your job to judge if a given subset of vertices can form a maximal clique.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers Nv (≤ 200), the number of vertices in the graph, and Ne, the number of undirected edges. Then Ne lines follow, each gives a pair of vertices of an edge. The vertices are numbered from 1 to Nv.

After the graph, there is another positive integer M (≤ 100). Then M lines of query follow, each first gives a positive number K (≤ Nv), then followed by a sequence of K distinct vertices. All the numbers in a line are separated by a space.

Output Specification:

For each of the M queries, print in a line Yes if the given subset of vertices can form a maximal clique; or if it is a clique but not a maximal clique, print Not Maximal; or if it is not a clique at all, print Not a Clique.

Sample Input:

8 10
5 6
7 8
6 4
3 6
4 5
2 3
8 2
2 7
5 3
3 4
6
4 5 4 3 6
3 2 8 7
2 2 3
1 1
3 4 3 6
3 3 2 1

Sample Output:

Yes
Yes
Yes
Yes
Not Maximal
Not a Clique

 

思路:

1、先判断是否是clique,即判断是否任意两边都相连;之后判断是否是maximal,即遍历所有不在集合中的剩余的点,看是否存在一个点满足和集合中所有的结点相连,最后如果都满足,那就输出Yes表示是Maximal cliqu

2、测试点1,3错误需要注意循环中有输出语句时要及时退出循环,防止重复输出

 

 

代码:

#include<stdio.h>
#include<vector>
using namespace std;
int main(){
    int Nv, Ne;    
    int E[205][205] ={0};
    scanf("%d%d", &Nv, &Ne);
    for(int i = 0; i < Ne; i++){
        int x, y;
        scanf("%d%d", &x, &y);
        E[x][y] = E[y][x] = 1;
    }
    int m;
    scanf("%d", &m);
    for(int i = 0; i < m; i++){
        int k;
        scanf("%d", &k);
        int u[205]; bool U[205] = {0};
        for(int j = 0; j < k; j++){
            scanf("%d", &u[j]);
            U[u[j]] = 1;
        }
        bool flag= true;
        for(int j = 0; j < k; j++){
            for(int w = 0; w < k && w != j; w++){
                if(!E[u[j]][u[w]]){
                    flag = false;
                    break;
                }
            }
        }
        if(!flag){
            printf("Not a Clique\n");
            continue;
        }else{
            bool flag1 = true;
            for(int j = 1; j <= Nv; j++){
                if(U[j])continue;
                bool flag2 = true;
                for(int w = 0; w < k; w++){
                    if(!E[u[w]][j]){
                        flag2 = false;
                        break;
                    }
                }
                if(flag2){
                    printf("Not Maximal\n");
                    flag1 = false;
                    break;
                }
            }
            if(flag1){
                printf("Yes\n");
                continue;
            }  
        }
    }
    return 0;
}

 

标签:1142,Maximal,测试点,int,Clique,vertices,clique,maximal,Yes
From: https://www.cnblogs.com/yccy/p/17677184.html

相关文章

  • app商城测试点
    原文:https://blog.csdn.net/qq_40807544/article/details/128287561购物车功能测试:1.页面是否与UI保持一致2.能否正常加入购物车3.账号未登录能否添加商品到购物车4.账号登录能否添加商品到购物车5.没有库存的商品是否可以加入购物车6.单个商品的数量上限最多能添加到购物车7.收......
  • CF803C Maximal GCD 题解
    题意构造一个长度为\(k\),和为\(n\)的严格单调递增序列,并最大化其最大公约数。(\(1\len,k\le10^{10}\))题解首先可以发现一个事实,这个序列的最大公约数一定为\(n\)的因子。所以我们可以考虑枚举\(n\)的所有因子并判断其能否成为整个序列的最大公约数。假设我们现在枚......
  • STM32F103C8T6测试点亮小灯
    目录代码代码#include"stm32f10x.h"//Deviceheaderintmain(void){ // 寄存器操作,stm32有很多寄存器,操作不方便,推荐使用标准库或HAL库// RCC->APB2ENR=0x00000010;// GPIOC->CRH=0x00300000;// GPIOC->ODR=0x00002000; //注意:步骤二中,需引......
  • Web安全测试点
    随着因特网的不断发展,人们对网络的使用越来越频繁,通过网络进行购物、支付等其他业务操作。而一个潜在的问题是网络的安全性如何保证,一些黑客利用站点安全性的漏洞来窃取用户的信息,使用户的个人信息泄漏,所以站点的安全性变得很重要。Web系统的安全性测试包括以下内容:(1)Web漏洞......
  • hdu 1142 A Walk Through the Forest
    WA了好多次了,大概是一直没搞清题意。题意:对边<a,b>,如果a到终点的距离小于b到终点的距离,那么b就可以到a,但是a就不能到b了,所以经过这样的一种筛选的方法之后,我们要在这样的图里寻找能从起点走到终点的路径的总数。思路:先算出每一点到终点的最小距离;然后dfs记忆化搜索路径总数。#incl......
  • CodeForces 1142E Pink Floyd
    洛谷传送门CF传送门感觉很神奇啊,想了挺久的。如果没有粉色边是容易的。竞赛图中,强连通分量缩点后,拓扑序较小的点向每一个拓扑序比它大的点连边。利用这个性质,我们维护一个答案集合\(S\),当\(|S|\ge2\)时,每次随意取出两个点\(u,v\inS\)。如果边的方向是\(u\tov\)......
  • 1699H - Maximal And
    思路:0.只有所有数这一位是1&结果才为11.想要得出最大值,高位越大越好所以从高位开始操作2.记录所有数字的每位为1的cnt[位数]++然后那位需要操作的次数为n-cnt[位数]3.优先执行:操作数给高位如果操作数不够使高位&后结果改变则给可以被改变的最高位4.终止条件:操作......
  • 功能测试——web功能测试点
    WEB测试方法总结-笔记一、输入框1、字符型输入框:(1)字符型输入框:英文全角、英文半角、数字、空或者空格、特殊字符“~!@#¥%……&*?[]{}”特别要注意单引号和&符号。禁止直接输入特殊字符时,使用“粘贴、拷贝”功能尝试输入。(2)长度检查:最小长度、最大长度、最小长度-1、最大长度+1、输入超......
  • 支付测试测试过程中需要注意的主要测试点及异常场景
    1.首先要保证接口都能正常调用; 2.生成一笔订单,支付完成后,同步或异步重复回调,只有一次有效;3.生成一笔订单,复制订单号和金额,再次生成一笔订单,用fiddler设置断点,用第一笔已完成订单号和订单金额去替换现有的订单号和金额,无法完成支付;4.生成一笔订单,跳转到第三方时修改金额,无法......
  • Educational Codeforces Round 20-C. Maximal GCD
    原题链接C.MaximalGCDtimelimitpertestmemorylimitpertestinputoutputn.Youshouldcreatesuch strictlyincreasing sequenceof k positivenumbers a1, a2, ..., ak,thattheirsumisequalto nGr......