// Ali
// #pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ins insert
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7, sze = 3e5+23, inf = 2e9, LG = 19,pr = 31;
int val[sze];
struct lan{
vector<int> parent;
vector<int> sz;
lan(int n){
parent.resize(n+23);
iota(all(parent),0);
sz.resize(n+23,1);
}
int root(int a){
if(parent[a]==a){
return a;
}
return parent[a]=root(parent[a]);
}
void unite(int a,int b){
int x = root(a);
int y = root(b);
if(x!=y){
if(sz[x]<sz[y]){
swap(x,y);
}
sz[x]+=sz[y];
parent[y]=x;
}
}
};
void fast(){
int n,m,qq;
cin>>n>>m>>qq;
vector<pair<pii,char>> q;
bool flag=false;
while(qq--){
string s;
cin>>s;
string a="";
string b="";
char op;
for(auto v:s){
if(v=='<' || v=='='){
op = v;
swap(a,b);
}
else{
a+=v;
}
}
swap(a,b);
q.pb({{stoll(a),stoll(b)},op});
// cout<<a<<" "<<op<<" "<<b<<endl;
if(op=='<' && !flag){
flag=true;
}
}
lan dsu(m+23);
if(flag){
vector<int> fk(m+23,0);
for(auto [vv,op]:q){
int a = vv.first;
int b = vv.second;
if(op=='='){
dsu.unite(a,b);
}
else{
val[a]=1;
val[b]=2;
}
}
for(int i =1;i<=m;i++){
// cout<<i<<" "<<dsu.root(i)<<" "<<val[i]<<endl;
fk[dsu.root(i)]|=val[i];
}
for(int i =1;i<=m;i++){
val[i]=fk[dsu.root(i)];
}
}
for(int i=1;i<=m;i++){
if(val[i]<=0){
cout<<"?"<<endl;
}
else{
cout<<"K"<<val[i]<<endl;
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
// cin>>tt;
while(tt--){
fast();
}
return 0;
}
Compilation message
kovanice.cpp: In function 'void fast()':
kovanice.cpp:66:9: warning: 'op' may be used uninitialized in this function [-Wmaybe-uninitialized]
66 | if(op=='<' && !flag){
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
9792 KB |
Output is correct |
2 |
Correct |
39 ms |
10432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
4036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
119 ms |
19868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |