Submission #584399

#TimeUsernameProblemLanguageResultExecution timeMemory
584399FatihSolakKOVANICE (COI15_kovanice)C++17
100 / 100
596 ms38268 KiB
#include <bits/stdc++.h> #define N 300005 using namespace std; int par[N]; int find(int a){ if(a == par[a])return a; return par[a] = find(par[a]); } bool merge(int a,int b){ a = find(a); b = find(b); if(a == b)return 0; par[a] = b; return 1; } vector<int> adj1[N]; vector<int> adj2[N]; int a[N],b[N]; char c[N]; int l[N],r[N]; int ans[N]; int n; void dfs1(int v){ if(l[v] != 1)return; for(auto u:adj1[v]){ dfs1(u); l[v] = max(l[v],l[u]+1); } } void dfs2(int v){ if(r[v] != n)return; for(auto u:adj2[v]){ dfs2(u); r[v] = min(r[v],r[u]-1); } } void solve(){ int m,v; cin >> n >> m >> v; for(int i = 1;i<=m;i++){ par[i] = i; l[i] = 1,r[i] = n; ans[i] = -1; } for(int i = 1;i<=v;i++){ cin >> a[i] >> c[i] >> b[i]; if(c[i] == '=') merge(a[i],b[i]); } for(int i = 1;i<=v;i++){ a[i] = find(a[i]); b[i] = find(b[i]); if(c[i] == '<'){ adj1[b[i]].push_back(a[i]); adj2[a[i]].push_back(b[i]); } } for(int i = 1;i<=m;i++){ if(i == find(i)){ dfs1(i); dfs2(i); if(l[i] == r[i]) ans[i] = l[i]; } } for(int i = 1;i<=m;i++){ if(ans[find(i)] == -1){ cout << "?" << endl; } else cout << "K" << ans[find(i)] << endl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; //cin >> t; while(t--){ solve(); } #ifdef Local cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds."; #endif }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...