乍一看,嗯,图论题,不错; 结果,这尼玛是模拟???? 传送链接:https://codeforces.com/contest/1228/problem/D 看了大佬的代码瞬间就明白了许多!!! #includecstdio#includecstring#includeiostrea
乍一看,嗯,图论题,不错;
结果,这尼玛是模拟????
传送链接:https://codeforces.com/contest/1228/problem/D
看了大佬的代码瞬间就明白了许多!!!
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #include<set> #define maxn 300300 using namespace std; int de[maxn]; vector<int>anc[100]; int n, m; int vis[maxn]; int dfn[maxn]; int flag = 0; set<pair<int, int>>ins; int main() { int be, en; scanf("%d %d", &n, &m); if (m == 0) { printf("-1\n"); return 0; } for (int i = 0; i < m; i++) { scanf("%d %d", &be, &en); ins.insert({ be,en }); ins.insert({ en,be }); } int cnt = 0; for (int i = 1; i <= n; i++) { if (dfn[i]) continue; cnt++; for (int j = i; j<=n ; j++) { if (ins.find({ i,j }) == ins.end()) { dfn[j] = cnt; anc[cnt].push_back(j); } } } if (cnt != 3 || anc[1].size() * anc[2].size() + anc[2].size() * anc[3].size() + anc[3].size() *anc[1].size() != m) { printf("-1\n"); return 0; } else { for (int i = 1; i <= 3; i++) { for (int j = i + 1; j <= 3; j++) { for (int k = 0; k < anc[i].size(); k++) { int x = anc[i][k]; for (int s = 0; s < anc[j].size(); s++) { int p = anc[j][s]; if (ins.find({ x, p }) == ins.end()) { printf("-1\n"); return 0; } } } } } } for (int i = 1; i <= n; i++) { printf("%d ", dfn[i]); } printf("\n"); return 0; }