This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define int long long
#define pb push_back
#define lim 300000
#define till 40001
// # of primes till 1e6 = 7e4
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
using pii = array<int,2>;
const int mod=1000000007ll;
unordered_map<int,int>parent;
int find(int i){
if(parent[i]==i)return i;
return parent[i]=find(parent[i]);
}
void unite(int i,int j){
int x=find(i),y=find(j);
parent[max(x,y)]=min(x,y);
}
void solve(){
int n,m,v;
cin>>n>>m>>v;
parent[-1]=-1;
parent[-2]=-2;
for(int i=0;i<m;i++){
parent[i]=i;
}
for(int i=0;i<v;i++){
int x,y;
char c;
cin>>x>>c>>y;
x--,y--;
if(c=='<'){
unite(x,-1);
unite(y,-2);
}
if(c=='>'){
unite(x,-2);
unite(y,-1);
}
if(c=='='){
unite(x,y);
}
}
for(int i=0;i<m;i++){
if(find(i)==-1){
cout<<"K1\n";
}
else if(find(i)==-2){
cout<<"K2\n";
} else{
cout<<"?\n";
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifdef Local
#ifndef INTERACTIVE
freopen("in","r",stdin);
#endif
freopen("out","w",stdout);
#endif
int t=1;
//cin>>t;
while (t--)
{
solve();
}
}
# | 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... |