# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
743620 | Trisanu_Das | KOVANICE (COI15_kovanice) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define int long long
int n, m, v;
vector<pair<int, int> > edges;
vector<int> adj[1000005];
int par[1000005];
void dfs(int u, int p){
if(par[i]) return;
par[i] = p;
for(int v : adj[u]) dfs(v, u);
}
vector< int > D[MAXN], R[MAXN]; int d[MAXN], r[MAXN];
int dfs_main(int u, vector< int > *D, int *d) {
if (d[i] != 0) return d[i];
for (int j : D[i]) d[i] = max(d[i], dfs_main(j, D, d));
return ++d[i];
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m >> v;
while(v--){
int a, b, char c; cin >> a >> c >> b;
if(c == '<') edges.push_back({a, b});
else{
adj[a].push_back(b); adj[b].push_back(a);
}
}
for(int i = 1; i <= m; i++) dfs(i, i);
for (auto e : E) {
D[com[e.first]].push_back(com[e.second]);
R[com[e.second]].push_back(com[e.first]);
}
for(int i = 1; i < m + 1; i++) dfs_main(par[i], D, d);
for(int i = 1; i < m + 1; i++) dfs_main(par[i], R, r);
for(int i = 1; i < m + 1; i++){
if(d[par[i]] + r[par[i]] - 1 == n) cout << 'K' << r[par[i]] << '\n';
else cout << "?\n";
}
}