Submission #203213

#TimeUsernameProblemLanguageResultExecution timeMemory
203213maruiiTeoretičar (COCI18_teoreticar)C++14
13 / 130
2637 ms60512 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; #define ff first #define ss second int L, R, M, ans[500005], cnt, D[200005]; bool vis[500005]; pii in[500005]; vector<pii> edge[200005]; int c; void dfs(int x, vector<int> &a, vector<int> &b) { while (edge[x].size()) { auto i = edge[x].back(); edge[x].pop_back(); if (vis[i.ss]) continue; vis[i.ss] = 1; D[x]--; D[i.ff]--; dfs(i.ff, a, b); c ^= 1; if (c) a.push_back(i.ss); else b.push_back(i.ss); } } void solve(vector<int> &v) { for (auto i : v) vis[i] = 0; vector<int> u; int flag = 1; for (auto i : v) { int x = in[i].ff, y = in[i].ss; if (!D[x]) u.push_back(x); if (!D[y]) u.push_back(y); if (D[x] || D[y]) flag = 0; edge[x].emplace_back(y, i); edge[y].emplace_back(x, i); D[x]++, D[y]++; } if (flag) { for (auto i : u) edge[i].clear(), D[i] = 0; ++cnt; for (auto i : v) ans[i] = cnt; return; } vector<int> a, b; for (auto i : u) if (D[i] & 1) dfs(i, a, b); for (auto i : u) if (D[i]) dfs(i, a, b); for (auto i : u) edge[i].clear(); solve(a); solve(b); } int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> L >> R >> M; vector<int> v; for (int i = 0; i < M; ++i) { int x, y; cin >> x >> y; in[i] = pii(x, L + y); v.emplace_back(i); } solve(v); printf("%d\n", *max_element(ans, ans + M)); for (int i = 0; i < M; ++i) printf("%d\n", ans[i]); 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...
#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...