Submission #846421

#TimeUsernameProblemLanguageResultExecution timeMemory
846421vjudge1KOVANICE (COI15_kovanice)C++17
0 / 100
101 ms5972 KiB
#include <bits/stdc++.h> #define endl "\n" #define pb push_back #define int long long using namespace std; const int inf = 2e18 + 5; const int N = 3e5 + 5; const int mod = 1e9 + 7; vector<int> par(N); int find(int a){ if(a == par[a]) return a; return par[a] = find(par[a]); } void merge(int a, int b){ a = find(a), b = find(b); par[a] = b; } int32_t main(){ //freopen("in.txt","r", stdin); int n, m, v; cin>>n>>m>>v; vector<array<int, 2> > type; vector<int> ans(m+1); for(int i = 0; i < v; i++){ string s; cin>>s; if(s[1] == '='){ merge(s[0] - '0', s[2] - '0'); } else{ int x = s[0] - '0', y = s[2] - '0'; x = find(x), y = find(y); ans[x] = 2; ans[y] = 1; } } for(int i = 1; i <= m; i++){ if(ans[find(i)]) cout<<"K"<<ans[find(i)]<<endl; else cout<<"?"<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...