看见顶点涂色,还以为要dfs啥的,没想到就是简单模拟,散列表是手动模拟的没用unordered_map
#include<iostream>
#include<cstring>
using namespace std;
const int N = 10010, M = 20003;
struct{
int a, b;
}edges[N];
int color[N];
int n, m;
int st[M], e[M], ne[M], idx;
void insert(int x){
int k = x % M;
e[idx] = x, ne[idx] = st[k], st[k] = idx ++;
}
int find(int x){
int k = x % M;
for(int i = st[k]; i != -1; i = ne[i]) if(e[i] == x) return 1;
return 0;
}
int main(){
cin >> n >> m;
for(int i = 1; i <= m; i ++){
int a, b;
cin >> a >> b;
edges[i] = {a, b};
}
int k;
cin >> k;
while(k --){
int type = 0;
memset(st, -1, sizeof st);
idx = 0;
for(int i = 0; i < n; i ++){
int c;
cin >> c;
color[i] = c;
if(!find(c)){
insert(c);
type ++;
}
}
int res = 1;
for(int i = 1; i <= m; i ++){
int a = edges[i].a, b = edges[i].b;
if(color[a] == color[b]){
res = 0;
break;
}
}
if(res) printf("%d-coloring
", type);
else puts("No");
}
return 0;
}