zoukankan      html  css  js  c++  java
  • 1142 Maximal Clique (25 分)

    1142 Maximal Clique (25 分)
     

    A 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 #include <bits/stdc++.h>
     2 using namespace std;
     3 int n,m,k,p;
     4 vector<int> v[250];
     5 int an[205], vis[205],val[205];
     6 int main(){
     7     cin >> n >> m;
     8     int x,y;
     9     for(int i = 0 ; i < m; ++i){
    10         cin >> x >> y;
    11         v[x].push_back(y);
    12         v[y].push_back(x);
    13     }
    14     cin >> k;
    15     while(k--){
    16         cin >> p;
    17         memset(vis,0,sizeof(vis));
    18         for(int i = 0; i < p; i++){
    19             cin >> an[i];
    20             for(int j = 0; j < v[an[i]].size(); ++j){
    21                 vis[v[an[i]][j]]++;
    22             }
    23         }
    24         bool flag = true;
    25         for(int i = 0; i < p; i++){
    26             if(vis[an[i]] != p-1){
    27                 flag = false;
    28                 break;
    29             }
    30         }
    31         if(!flag){
    32             printf("Not a Clique
    ");
    33             continue;
    34         }
    35         bool prime = true;
    36         for(int i = 1; i <= n; i++){
    37             if(vis[i] == p){
    38                 prime = false;
    39                 break;
    40             }
    41         }
    42         if(prime)
    43             printf("Yes
    ");
    44         else
    45             printf("Not Maximal
    ");
    46     }
    47     return 0;
    48 }






  • 相关阅读:
    php中"::"双冒号有什么作用
    微信公众平台中的openid是什么?
    微信支付:“当前页面的URL未注册”
    HTTPS的一些疑问解答
    傻瓜式十分钟免费开启 HTTPS,是时候为你的站点加上小绿锁了
    微信支付开发(1) JS API支付V3版(转)
    php支付宝接口用法
    DedeCMS Error: (PHP 5.3 and above) Please set request_order
    使用 Laravel 框架:成为微信公众平台开发者
    thread线程栈size及局部变量最大可分配size【转】
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/11285671.html
Copyright © 2011-2022 走看看