老太太钻被窝,给爷整笑了。
测试点2: 颜色只能是k种,大于小于都过不去。
#include <bits/stdc++.h>
using namespace std;
int edges[503][503];
int color[503];
int main() {
int v, e, k;
cin >> v >> e >> k;
for (int i = 0; i < e; i++) {
int a, b;
cin >> a >> b;
edges[a][b] = 1;
edges[b][a] = 1;
}
int m;
cin >> m;
while (m--) {
set<int> st;
for (int i = 1; i <= v; i++) {//顶点颜色
cin >> color[i];
st.insert(color[i]);
}
if (st.size()!= k) {
cout << "No" << endl;
continue;
}
int flag = 1;
for (int i = 1; flag && i <= v; i++) {//对于第i个顶点
int c = color[i];
for (int j = 1; j <= v; j++) {//遍历其相邻顶点
if (edges[i][j] && color[j] == c) {//如果相邻的涂了同一种颜色
flag = 0;
cout << "No" << endl;
break;
}
}
}
if (flag) {
cout << "Yes" << endl;
}
}
return 0;
}
标签:int,cin,st,着色,color,edges,L2,023,503
From: https://www.cnblogs.com/chengyiyuki/p/18081336