这道题的题意没看懂,看了解析才勉强懂
题意就是先输入的这些是一个边的两个端点
第二个输入的是每个点的颜色
要做的就是判断每条边的两个点的颜色是否相同,不相同就输出一共有的颜色种类
用set进行颜色的筛选
用结构体存储节点,直接判断
错误的点再记得区分哪里用m,n,不要混
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <cmath>
#include <map>
#include <set>
using namespace std;
int m,n,k;
struct node{
int v1;
int v2;
};
int main(){
cin >> n >> m;
vector<node> no(m);
for(int i=0; i<m; i++){
//cin >> no[i].v1 >> no[i].v2;
scanf("%d %d", &no[i].v1, &no[i].v2);
}
cin >> k;
while(k--){
set<int> ans;
int a[10009] = {0};
bool key = true;
for(int j=0; j<n; j++){
//cin >> a[j];
scanf("%d",&a[j]);
ans.insert(a[j]);
}
for(int l=0; l<m; l++){
if(a[no[l].v1] == a[no[l].v2]){
key = false;
break;
}
}
if(key)
cout << ans.size() << "-coloring" << endl;
else
cout << "No" << endl;
ans.clear();
}
return 0;
}