This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize ("O1")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define F first
#define S second
#define ll long long
//#define int ll
#define pii pair<int, int>
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846
#define all(v) v.begin(), v.end()
#define pss pair<string, string>
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define imp cout<<-1<<endl;
#define flu cout.flush();
#define Endl endl
const int N = 300009;
const int mod = 1e9+7;
vector<int>a[N];
map<int, int>ans;
int used[N];
void dfs(int node, int val){
ans[node]=val;
used[node]++;
for(int i : a[node]){
if(used[i]==0){
dfs(i, val);
}
}
}
void solve(){
int n, m, q;
cin>>n>>m>>q;
int yx=0;
vector<int>one, two;
for(int i=0; i<q; i++){
string s;
cin>>s;
int e1=0, e2=0, fi=0;
char sym;
int n=s.size();
for(int i=0; i<n; i++){
if(s[i]=='<' or s[i]=='>' or s[i]=='='){
sym=s[i];
fi++;
continue;
}
if(fi==0){
e1=e1*10+(int(s[i])-48);
}
else{
e2=e2*10+(int(s[i])-48);
}
}
if(sym!='='){
if(sym=='>'){
swap(e1, e2);
}
one.pb(e1);
ans[e1]=1;
two.pb(e2);
ans[e2]=2;
yx++;
}
if(sym=='='){
a[e1].pb(e2);
a[e2].pb(e1);
}
}
for(int i : one){
if(used[i]==0){
dfs(i, 1);
}
}
for(int i : two){
if(used[i]==0){
dfs(i, 2);
}
}
for(int i=1; i<=m; i++){
if(ans[i]==1){
cout<<"K1"<<endl;
}
else if(ans[i]==2){
cout<<"K2"<<endl;
}
else{
cout<<"?"<<endl;
}
}
}
signed main(){
io;
int t=1;
//cin>>t;
while(t--){
solve();
}
}
Compilation message (stderr)
kovanice.cpp: In function 'void solve()':
kovanice.cpp:65:13: warning: 'sym' may be used uninitialized in this function [-Wmaybe-uninitialized]
65 | if(sym=='>'){
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |