제출 #846246

#제출 시각아이디문제언어결과실행 시간메모리
846246vjudge1KOVANICE (COI15_kovanice)C++17
0 / 100
358 ms39448 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[find(node)]!=-1) return; dep[find(node)]=1; for(auto i:edges[find(node)]){ dfs(find(i)); dep[find(node)]=max(dep[find(node)], dep[find(i)]+1); } } void mark(int node){ if(ans[find(node)]!="?") return; ans[find(node)] = "K"; ans[find(node)] += to_string(dep[find(node)]); for(auto i:edges[find(node)]){ if(dep[find(i)]==dep[find(node)]-1){ mark(find(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(find(a),find(b)); } else later.pb(s); } for(auto s:later){ int a=s[0]-'0', b=s[2]-'0'; edges[find(b)].pb(find(a)); } if(n==2){ for(int i=1; i<=m; i++){ if(edges[find(i)].size()>0){ ans[find(i)]="K2"; } for(auto j:edges[find(i)]){ ans[find(j)]="K1"; } } for(int i=1; i<=m; i++){ //cerr << find(i) << endl; cout << ans[find(i)]; if(i!=m) cout << endl; } return; } for(int i=1; i<=m; i++){ dfs(find(i)); } for(int i=1; i<=m; i++){ if(dep[find(i)]==-1) cerr << "wtf" << endl; 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...