Submission #1066671

#TimeUsernameProblemLanguageResultExecution timeMemory
1066671thinknoexitAlternating Current (BOI18_alternating)C++17
55 / 100
5 ms604 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 1010; vector<int> v[N]; int adjm[N][N], l[N], r[N], bit[N]; bool vis[N][N], in[N]; vector<int> adj[N]; int col[N], ans[N]; bool bipartite(int v, int c = 1) { if (col[v]) return col[v] == c; col[v] = c; for (auto& x : adj[v]) { if (!bipartite(x, 3 - c)) return false; } return true; } int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0;i < m;i++) { cin >> l[i] >> r[i]; l[i]--, r[i]--; int nl = l[i], nr = r[i]; for (;nl != nr;nl = (nl + 1) % n) { if ((int)v[nl].size() <= 2) v[nl].push_back(i); } if ((int)v[nr].size() <= 2) v[nr].push_back(i); } for (int i = 0;i < n;i++) { if ((int)v[i].size() <= 1) { cout << "impossible\n"; return 0; } } for (int i = 0;i < n;i++) { if ((int)v[i].size() == 2) { in[v[i][0]] = in[v[i][1]] = 1; adj[v[i][0]].push_back(v[i][1]); adj[v[i][1]].push_back(v[i][0]); } } for (int i = 0;i < m;i++) { if (in[i] && !col[i]) { if (!bipartite(i)) { cout << "impossible\n"; return 0; } } } for (int i = 0;i < m;i++) col[i]--; for (int i = 0;i < n;i++) { int bit = 0; for (auto& x : v[i]) { if (col[x] != -1) bit |= (1 << col[x]); } if (bit == 3) continue; if (!(bit & 1)) { for (auto& x : v[i]) { if (col[x] != -1) continue; col[x] = 0; break; } } if (!(bit & 2)) { for (auto& x : v[i]) { if (col[x] != -1) continue; col[x] = 1; break; } } } for (int i = 0;i < m;i++) { if (col[i] == -1) col[i] = 0; cout << col[i]; } cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...