fork(2) download
  1. #include <bits/stdc++.h>
  2. #define pi 3.14159265359
  3. using namespace std;
  4.  
  5. int main() {
  6. int N,M,K;
  7. cin >> N >> M >> K;
  8. vector< vector<int> > G(N,vector<int>(N,0));
  9. for(int i =0; i < M; i++) {
  10. int a,b;
  11. cin >> a >> b;
  12. G[--a][--b]++;
  13. G[b][a]++;}
  14. vector<int> part(N,-1);
  15. map<int,int> m;
  16. for(int i =0; i < N; i++) if(part[i] == -1) {
  17. part[i] =i;
  18. m[i] =0;
  19. for(int j =i+1; j < N; j++) if(G[i][j] == 0) {
  20. if(part[j] != -1) {cout << "-1\n"; return 0;}
  21. part[j] =i;}
  22. }
  23. else if(G[part[i]] != G[i]) {cout << "-1\n"; return 0;}
  24.  
  25. int a =0;
  26. for(auto it =m.begin(); it != m.end(); it++) it->second =a++;
  27. if(m.size() > K) {cout << "-1\n"; return 0;}
  28. vector<int> ans(N);
  29. for(int i =0; i < N; i++) cout << m[part[i]]+1 << ((i == N-1)?"\n":" ");
  30. return 0;}
Success #stdin #stdout 0s 3480KB
stdin
4 4 3
1 2
1 3
1 4
2 3
stdout
-1