#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
vector<pair<int,int>>v[300005];
int vis[300005],ans[300005];
void dfs(int node,int x){
vis[node]=1;
ans[node]=x;
for(auto i:v[node]){
if(vis[i.ff])continue;
dfs(i.ff,x^i.ss);
}
return;
}
int32_t main(){
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=m;i++)ans[i]=-1;
vector<pair<int,int>>v2;
for(int i=0;i<k;i++){
string s;
cin>>s;
int a=0,b=0;
string s2,s3;
int ind=0;
while(s[ind]!='<' && s[ind]!='='){
s2+=s[ind];
ind++;
}
int temp=ind;
ind++;
while(ind<s.size()){
s3+=s[ind];
ind++;
}
a=stoi(s2);
b=stoi(s3);
if(s[temp]=='='){
v[a].pb({b,0});
v[b].pb({a,0});
}
else{
v[a].pb({b,1});
v[b].pb({a,1});
v2.pb({a,0});
v2.pb({b,1});
}
}
for(auto i:v2){
if(vis[i.ff])continue;
dfs(i.ff,i.ss);
}
for(int i=1;i<=m;i++){
if(ans[i]==-1)cout<<"?"<<endl;
else cout<<"K"<<ans[i]+1<<endl;
}
}
Compilation message
kovanice.cpp: In function 'int32_t main()':
kovanice.cpp:42:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | while(ind<s.size()){
| ~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8024 KB |
Output is correct |
2 |
Correct |
4 ms |
8028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
287 ms |
19388 KB |
Output is correct |
2 |
Correct |
285 ms |
19388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
33 ms |
16320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
587 ms |
38044 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |