Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #pragma GCC optimize("Ofast")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
- // #pragma GCC optimize("unroll-loops")
- // #pragma GCC optimize("fast-math")
- #include <bits/stdc++.h>
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- // typedef __int128 tll;
- // #define _CRT_DISABLE_PERFCRIT_LOCKS
- #define rall(a) a.rbegin(), a.rend()
- #define all(a) a.begin(), a.end()
- #define pb push_back
- #define pf push_front
- #define forn(i, x) for (int i = 0; i < x; ++i)
- #define int long long
- using namespace std;
- int cnt(int a, int b) {
- return a / b + (a % b > 0);
- }
- int intlog(double base, double x) {
- return ceil(log(x) / log(base));
- }
- int binpow(int n, int base) {
- if (base == 0) return 1;
- if (base == 1) return n;
- return (base % 2 == 1 ? binpow(n, base - 1) * n : binpow(n, base / 2) * binpow(n, base / 2));
- }
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n, m; cin >> n >> m;
- vector<set<int>> vst(n);
- set<int> fi, se, th;
- fi.insert(0);
- for (int i = 0; i < m; ++i) {
- int a, b; cin >> a >> b;
- --a, --b;
- vst[a].insert(b);
- vst[b].insert(a);
- }
- int sec = -1;
- for (int i = 1; i < n; ++i) if (!vst[i].count(0)) fi.insert(i);
- for (int i = 1; i < n; ++i) if (!fi.count(i)) sec = i;
- if (sec == -1) {
- cout << -1;
- exit(0);
- }
- se.insert(sec);
- for (int i = 1; i < n; ++i) if (!vst[i].count(sec)) se.insert(i);
- int thi = -1;
- for (int i = 1; i < n; ++i) if (!se.count(i) && !fi.count(i)) thi = i;
- if (thi == -1) {
- cout << -1;
- exit(0);
- }
- th.insert(thi);
- for (int i = 1; i < n; ++i) if (!vst[i].count(thi)) th.insert(i);
- if (se.size() + fi.size() + th.size() != n) {
- cout << -1;
- exit(0);
- }
- int s = se.size(), f = fi.size(), t = th.size();
- if ((s * (f + t) + f * (s + t) + t * (f + s)) / 2 != m) {
- cout << -1;
- exit(0);
- }
- for (int i = 0; i < n; ++i) {
- if (fi.count(i)) {
- cout << 1 << " ";
- } else if (se.count(i)) {
- cout << 2 << " ";
- } else if (th.count(i)) {
- cout << 3 << " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement