Submission #846137

#TimeUsernameProblemLanguageResultExecution timeMemory
846137vjudge1KOVANICE (COI15_kovanice)C++17
0 / 100
363 ms39944 KiB
#pragma GCC optimize("unroll-loops,Ofast,O3") #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define spc << " " << #define all(x) x.begin(), x.end() #define ll long long #define int long long #define ii pair<int,int> #define vi vector<int> #define vii vector<ii> #define st first #define nd second #define inf 1000000009 #define MOD 998244353 using namespace std; int dad[300005]; string ans[300005]; int dep[300005]; vi edges[300005]; int find(int x){ if(dad[x]==x) return x; return dad[x]=find(dad[x]); } void unite(int x, int y){ dad[find(x)]=find(y); } void dfs(int node){ if(dep[node]!=-1) return; dep[node]=1; for(auto i:edges[node]){ dfs(i); dep[node]=max(dep[node], dep[i]+1); } } void mark(int node){ if(ans[node]!="?") return; ans[node] = "K"; ans[node] += to_string(dep[node]); for(auto i:edges[node]){ if(dep[i]==dep[node]-1){ mark(i); } } } void solve(){ int n, m, v; cin >> n >> m >> v; for(int i=1; i<=m; i++){ dad[i]=i; ans[i]="?"; dep[i]=-1; } vector<string> later; for(int i=1; i<=v; i++){ string s; cin >> s; int a=s[0]-'0', b=s[2]-'0'; if(s[1]=='='){ unite(a,b); } else later.pb(s); } for(auto s:later){ int a=s[0]-'0', b=s[2]-'0'; if(s[1]=='<'){ edges[find(b)].pb(find(a)); } else edges[find(a)].pb(find(b)); } for(int i=1; i<=m; i++){ dfs(find(i)); } for(int i=1; i<=m; i++){ if(dep[find(i)]==n) mark(find(i)); } for(int i=1; i<=m; i++){ cout << ans[find(i)] << endl; } } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0); #ifdef Local freopen("in.txt","r",stdin); freopen("out","w",stdout); #endif ll t=1; //cin >> t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...