Submission #1121081

#TimeUsernameProblemLanguageResultExecution timeMemory
1121081AtabayRajabliKOVANICE (COI15_kovanice)C++17
50 / 100
2058 ms23880 KiB
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define int long long using namespace std; const int sz = 3e5 + 5; int n, m, v, p[sz], a[sz], b[sz], dp[sz], ans[sz]; char c[sz]; vector<int> g[sz]; int par(int x) { if(p[x] < 0) return x; return p[x] = par(p[x]); } bool join(int u, int v) { u = par(u), v = par(v); if(u == v) return 0; if(p[u] > p[v]) swap(u, v); p[u] += p[v]; p[v] = u; return 1; } void dfs(int v) { dp[v] = 1; for(int i : g[v]) { if(!dp[i]) dfs(i); dp[v] = max(dp[v], dp[i] + 1); } } void dfs(int v, int dist) { ans[v] = dist; for(int i : g[v]) { if(dp[i] == dp[v] - 1) { dfs(i, dist + 1); } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> v; fill(p, p + sz, -1); for(int i = 1; i <= v; i++) { cin >> a[i] >> c[i] >> b[i]; if(c[i] == '=') { join(a[i], b[i]); } } for(int i = 1; i <= v; i++) { if(c[i] == '<') { g[par(a[i])].push_back(par(b[i])); } } for(int i = 1; i <= m; i++) { if(p[par(i)] < 0 && !dp[par(i)]) { dfs(par(i)); } } for(int i = 1; i <= m; i++) { if(p[par(i)] < 0 && dp[par(i)] == n && !ans[par(i)]) { dfs(par(i), 1); } } for(int i = 1; i <= m; i++) { if(ans[par(i)]) cout << "K" << ans[par(i)]; else cout << "?"; 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...