题意:给出一个图,定义这样一个结点子集subset,若subset中的任意两结点不都相邻,则称之为Not a Clique;若subset中的任意两结点都相邻,则称之为Clique;若subset中的结点不仅都相邻,而且不存在subset之外的点与subset中的每个结点都相邻,则称之为Maximal。

思路:首先,判断待查询的结点是否都相邻;其次,判断是不是Maximal。怎么判断呢?遍历所有subset之外的结点(可以用vis[]数组来表示,标记subset[]里的结点为true,这样就只会访问非subset的点了),只要存在这样一个结点v,使得v与subset中的每个结点都相邻,则说明subset不是Maximal。

代码:

#include <cstdio>
#include <cstring>
;
};
int subset[maxn];//存放每次检查的结点
int vis[maxn];//标记在集合中出现过的结点
int n,m;

int main()
{
    scanf("%d%d",&n,&m);
    int u,v;
    while(m--){
        scanf("%d%d",&u,&v);
        graph[u][v]=graph[v][u]=;
    }
    int query,k;
    scanf("%d",&query);
    while(query--){
        scanf("%d",&k);
        memset(vis,,sizeof(vis));//每次查询前记得初始化
        ;i<k;i++){
            scanf("%d",&subset[i]);
            vis[subset[i]]=;
        }

        ;//1->Yes; 0->Not Maximal; -1->Not a Clique
        //1.检验是不是Clique
        ;i<k;i++){
            ) break;
            ;j<k;j++){
                ) {
                        flag=-;
                        break;
                }
            }
        }
        ){
            printf("Not a Clique\n");
            continue;
        }
        //2.检验是不是Maximal
        ;v<=n;v++){
            if(vis[v]) continue;
            vis[v]=;
            ;
            for(;i<k;i++)
                ) break;
            if(i==k){
                flag=;//但凡存在一个不是subset中的结点使得该结点与subset中的每个结点都相连,说明它不是Maximal
                break;
            }
        }//for
        ) printf("Yes\n");
        else printf("Not Maximal\n");
    }
    ;
}

1142 Maximal Clique的更多相关文章

  1. PAT 1142 Maximal Clique[难]

    1142 Maximal Clique (25 分) A clique is a subset of vertices of an undirected graph such that every t ...

  2. [PAT] 1142 Maximal Clique(25 分)

    1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...

  3. PAT 甲级 1142 Maximal Clique

    https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552 A clique is a subset o ...

  4. PAT 1142 Maximal Clique

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  5. 1142. Maximal Clique (25)

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  6. A1142. Maximal Clique

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  7. PAT A1142 Maximal Clique (25 分)——图

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  8. PAT_A1142#Maximal Clique

    Source: PAT A1142 Maximal Clique (25 分) Description: A clique is a subset of vertices of an undirect ...

  9. PTA 1140 1141 1142 1143

    1140 Look-and-say Sequence 思路:模拟 #include<bits/stdc++.h> using namespace std; typedef long lon ...

随机推荐

  1. bootstrap框架:常用内容一

    <!DOCTYPE html><html lang="zh-CN"> <head> <meta charset="utf-8&q ...

  2. LeetCode第[26]题(Java):Remove Duplicates from Sorted Array 标签:Array

    题目难度:Easy 题目: Given a sorted array, remove the duplicates in-place such that each element appear onl ...

  3. ssh整合学习(1)

    Hibernate框架 1 hibernate核心配置文件 (0)orm思想 -对象关系映射 (1)数据库信息 (2)hibernate信息 (3)映射配置 (4)hibernate核心配置文件 -如 ...

  4. spring3: 依赖和依赖注入-xml配置-DI的配置

    3.1.1  依赖和依赖注入 传统应用程序设计中所说的依赖一般指“类之间的关系”,那先让我们复习一下类之间的关系: 泛化:表示类与类之间的继承关系.接口与接口之间的继承关系: 实现:表示类对接口的实现 ...

  5. CodeForces 385 D.Bear and Floodlight 状压DP

    枚举灯的所有可能状态(亮或者不亮)(1<<20)最多可能的情况有1048576种 dp[i]表示 i 状态时灯所能照射到的最远距离(i 的二进制中如果第j位为0,则表示第j个灯不亮,否则就 ...

  6. 对CSS了解-overflow:hidden

    overflow:hidden 列出我在项目中,运用到此属性的例子: (1)暴力清除浮动 <style type="text/css"> .wrap {;backgro ...

  7. C++程序设计之提高效率

    设计C++程序时,总结起来可以从如下几点提高效率: 1.并发 2.异步 3.缓存

  8. 017——VUE中v-fo指令的使用方法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. ZOJ 3211 Dream City(线性DP)

    Dream City Time Limit: 1 Second      Memory Limit: 32768 KB JAVAMAN is visiting Dream City and he se ...

  10. canvas - 柱子效果

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...