Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. // #pragma GCC optimize("Ofast")
  2. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
  3. // #pragma GCC optimize("unroll-loops")
  4. // #pragma GCC optimize("fast-math")
  5.  
  6. #include <bits/stdc++.h>
  7.  
  8. typedef unsigned long long ull;
  9. typedef long long ll;
  10. typedef long double ld;
  11. // typedef __int128 tll;
  12.  
  13. // #define _CRT_DISABLE_PERFCRIT_LOCKS
  14. #define rall(a) a.rbegin(), a.rend()
  15. #define all(a) a.begin(), a.end()
  16. #define pb push_back
  17. #define pf push_front
  18. #define forn(i, x) for (int i = 0; i < x; ++i)
  19. #define int long long
  20.  
  21. using namespace std;
  22.  
  23. int cnt(int a, int b) {
  24. return a / b + (a % b > 0);
  25. }
  26.  
  27. int intlog(double base, double x) {
  28. return ceil(log(x) / log(base));
  29. }
  30.  
  31. int binpow(int n, int base) {
  32. if (base == 0) return 1;
  33. if (base == 1) return n;
  34. return (base % 2 == 1 ? binpow(n, base - 1) * n : binpow(n, base / 2) * binpow(n, base / 2));
  35. }
  36.  
  37. signed main() {
  38. ios_base::sync_with_stdio(0);
  39. cin.tie(0);
  40. cout.tie(0);
  41.  
  42. int n, m; cin >> n >> m;
  43. vector<set<int>> vst(n);
  44. set<int> fi, se, th;
  45. fi.insert(0);
  46.  
  47. for (int i = 0; i < m; ++i) {
  48. int a, b; cin >> a >> b;
  49. --a, --b;
  50. vst[a].insert(b);
  51. vst[b].insert(a);
  52. }
  53.  
  54. int sec = -1;
  55.  
  56. for (int i = 1; i < n; ++i) if (!vst[i].count(0)) fi.insert(i);
  57.  
  58. for (int i = 1; i < n; ++i) if (!fi.count(i)) sec = i;
  59.  
  60. if (sec == -1) {
  61. cout << -1;
  62. exit(0);
  63. }
  64.  
  65. se.insert(sec);
  66.  
  67. for (int i = 1; i < n; ++i) if (!vst[i].count(sec)) se.insert(i);
  68.  
  69. int thi = -1;
  70.  
  71. for (int i = 1; i < n; ++i) if (!se.count(i) && !fi.count(i)) thi = i;
  72.  
  73. if (thi == -1) {
  74. cout << -1;
  75. exit(0);
  76. }
  77.  
  78. th.insert(thi);
  79.  
  80. for (int i = 1; i < n; ++i) if (!vst[i].count(thi)) th.insert(i);
  81.  
  82. if (se.size() + fi.size() + th.size() != n) {
  83. cout << -1;
  84. exit(0);
  85. }
  86.  
  87. int s = se.size(), f = fi.size(), t = th.size();
  88.  
  89. if ((s * (f + t) + f * (s + t) + t * (f + s)) / 2 != m) {
  90. cout << -1;
  91. exit(0);
  92. }
  93.  
  94. for (int i = 0; i < n; ++i) {
  95. if (fi.count(i)) {
  96. cout << 1 << " ";
  97. } else if (se.count(i)) {
  98. cout << 2 << " ";
  99. } else if (th.count(i)) {
  100. cout << 3 << " ";
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement