【1142】Maximal Clique (25分)【有点问题】

简介: 【1142】Maximal Clique (25分)【有点问题】【1142】Maximal Clique (25分)【有点问题】
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>  
#include<map>
#include<vector>
#include<queue> 
#include<unordered_map>
using namespace std;  
const int MAXV=205;
vector<vector<int>>graph(MAXV);
int main(){   
  int Nv,Ne,M;
  scanf("%d%d",&Nv,&Ne);//点数 边数
  while(Ne--){//读取无向图的边
    int a,b;
    scanf("%d%d",&a,&b);
    graph[b].push_back(a);
    graph[a].push_back(b);
  }
  scanf("%d",&M);
  while(M--){
    int K;
    scanf("%d",&K);
    unordered_map<int,int>record;
    //键表示读取的点集能够到达的顶点编号
    //值表示读取的点集有多少个点能够到达键代表的顶点
    vector<int>v(K);
    //存储读入的点集中各个顶点编号,集合有K个点
    for(int i=0;i<K;++i){
      scanf("%d",&v[i]);
      ++record[v[i]];//递增当前点在map中对应的值
      for(int ii:graph[v[i]])//遍历其能到达的顶点
        ++record[ii];//递增能够到达的点在map中对应的值
    }
    bool clique=true,maximal=true;
    for(auto i=record.cbegin();i!=record.cend()&&clique;++i){
      //遍历map
      auto j=find(v.cbegin(),v.cend(),i->first);//返回record~map以i为键值对应值的指针
      if(j!=v.cend()&&i->second!=K)//j未到末尾且
      //当前map的键代表的顶点编号在vector中且其值≠K
        clique=false;
      else if(j==v.cend()&&i->second==K)
      //当前map的键代表的顶点编号不在vector中且值=K
        maximal=false;
    }
    //输出
    if(!clique)
      printf("Not a Clique\n");
    else if(!maximal)
      printf("Not Maximal\n");
    else
      printf("Yes\n");
  }
  system("pause");
    return 0;   
}
相关文章
PAT甲级 1004. Counting Leaves(30分)
PAT甲级 1004. Counting Leaves(30分)
66 0
|
人工智能 BI
AtCoder Beginner Contest 216 F - Max Sum Counting (降维 背包dp)
AtCoder Beginner Contest 216 F - Max Sum Counting (降维 背包dp)
130 0
Optimal Coin Change(完全背包计数)
题目描述 In a 10-dollar shop, everything is worthy 10 dollars or less. In order to serve customers more effectively at the cashier, change needs to be provided in the minimum number of coins. In this problem, you are going to provide a given value of the change in different coins.
90 0
【1096】Consecutive Factors (20 分)
【1096】Consecutive Factors (20 分) 【1096】Consecutive Factors (20 分)
123 0
【1087】All Roads Lead to Rome (30 分)
【1087】All Roads Lead to Rome (30 分) 【1087】All Roads Lead to Rome (30 分)
118 0