完全子图
判断是否完全子图 每个点都与其他点有边 n^2
峰会https://www.acwing.com/problem/content/4281/
这道题数据范围非常小,暴力即可。
- 枚举这一区域的任意两位首脑是否都是朋友。
- 如果不是,直接输出 Area X needs help.。
- 否则,枚举其他首脑能否到这个休息区。
- 如果没有首脑能加入则输出 Area X is OK.。
- 否则输出 Area X may invite more people, such as H.,其中 H 是额外可被安排的人的编号(如果不唯一,则输出最小的那个)。
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 210;
int n,m;
int g[N][N];
bool st[N];
int main()
{
cin >> n>>m;
while (m -- ){
int a,b;
cin >> a>>b;
g[a][b]=g[b][a]=true;
}
cin >> m;
for (int t = 1; t <= m; t ++ ){
int cnt;cin>>cnt;//每次测试看看这里面的点是不是完全图
memset(st, 0, sizeof st);
while (cnt -- ){
int x;cin>>x;
st[x]=true;//表示这些点在集合里面
}
bool iswanquan=true;
for(int i=0;i<=n;i++){
for (int j = i+1; j <= n; j ++ ){
if(st[i]&&st[j]&&!g[i][j]){
iswanquan=false;//发现在这个集合里面的点 存在没有边的话
}
}
}
if(!iswanquan){
printf("Area %d needs help.\n",t);
}else{
int id=0;
for (int i = 1; i <= n; i ++ ){//枚举其他点
if(!st[i]){//不在集合里
bool all=true;
for (int j = 1; j <= n; j ++ ){//
if(st[j]&&!g[i][j]){//但是和在集合里面的点都有边的话
all= false;
break;
}
}
if(all){
id=i;
break;
}
}
}
if(id) printf("Area %d may invite more people, such as %d.\n",t,id);
else printf("Area %d is OK.\n",t);
}
}
return 0;
}