Submission #1121112

#TimeUsernameProblemLanguageResultExecution timeMemory
1121112OmarAlimammadzadeKOVANICE (COI15_kovanice)C++14
0 / 100
162 ms28956 KiB
// author - alimammadzade #include <bits/stdc++.h> #define int long long using namespace std; const int N = 3e5 + 1; vector<int> g[N][2], Kn; int p[N], res[N], out[N], n, m, k; bool vis[N]; int _find(int u) { return (p[u] < 0 ? u : p[u] = _find(p[u])); } void _union(int u, int v) { if (u == v) return; if (p[u] > p[v]) swap(u, v); p[u] += p[v]; p[v] = u; } void dfs1(int u) { vis[u] = 1; for (int v : g[u][0]) if (!vis[v]) { dfs1(v); out[u] = max(out[u], out[v] + 1); } } void dfs2(int u) { vis[u] = 1; res[u] = out[u]; for (int v : g[u][0]) if (!vis[v] && out[v] == out[u] - 1) dfs2(v); } signed main() { cin.tie(nullptr)->sync_with_stdio(false); // system("cls"), freopen("in.txt", "r", stdin); fill(p, p + N, -1); fill(out, out + N, 1); cin >> n >> m >> k; while (k--) { int u, v; char c; cin >> u >> c >> v; u = _find(u); v = _find(v); if (c == '=') _union(u, v); else if (c == '>') g[u][0].push_back(v), g[v][1].push_back(u); else g[v][0].push_back(u), g[u][1].push_back(v); } for (int i = 1; i <= m; i++) if (i == _find(i) && g[i][1].empty()) { if (!vis[i]) dfs1(i); if (out[i] == n) Kn.push_back(i); } fill(vis, vis + N, false); for (int i : Kn) dfs2(i); for (int i = 1; i <= m; i++) if (res[_find(i)]) cout << 'K' << res[_find(i)] << '\n'; else cout << "?\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...