#include <bits/stdc++.h>
#define N 300005
using namespace std;
int par[N];
int find(int a){
if(a == par[a])return a;
return par[a] = find(par[a]);
}
bool merge(int a,int b){
a = find(a);
b = find(b);
if(a == b)return 0;
par[a] = b;
return 1;
}
vector<int> adj[N];
int a[N],b[N];
char c[N];
bool ok[N];
bool vis[N];
int ans[N];
vector<int> ord;
void dfs(int v){
vis[v] = 1;
for(auto u:adj[v]){
if(vis[u])continue;
dfs(u);
}
ord.push_back(v);
}
void solve(){
int n,m,v;
cin >> n >> m >> v;
for(int i = 1;i<=m;i++){
par[i] = i;
ok[i] = 1;
ans[i] = -1;
}
for(int i = 1;i<=v;i++){
cin >> a[i] >> c[i] >> b[i];
if(c[i] == '=')
merge(a[i],b[i]);
}
for(int i = 1;i<=v;i++){
a[i] = find(a[i]);
b[i] = find(b[i]);
if(c[i] == '<'){
ans[a[i]] = 1;
ans[b[i]] = 2;
//ok[a[i]] = 0;
//adj[b[i]].push_back(a[i]);
}
}
/*
for(int i = 1;i<=m;i++){
if(ok[i] && i == find(i)){
ord.clear();
dfs(i);
for(int j = 0;j<ord.size();j++){
vis[ord[j]] = 0;
if(ord.size() == n){
ans[ord[j]] = j+1;
}
}
}
}*/
for(int i = 1;i<=m;i++){
if(ans[find(i)] == -1){
cout << "?" << endl;
}
else cout << "K" << ans[find(i)] << endl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while(t--){
solve();
}
#ifdef Local
cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds.";
#endif
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
252 ms |
10532 KB |
Output is correct |
2 |
Correct |
257 ms |
11756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
8276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
455 ms |
13584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |