#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define all(x) x.begin(), x.end()
#define ll long long
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 998244353
using namespace std;
int dad[300005];
string ans[300005];
int dep[300005];
set<int> edges[300005];
int find(int x){
if(dad[x]==x) return x;
return dad[x]=find(dad[x]);
}
void unite(int x, int y){
dad[find(x)]=find(y);
}
void dfs(int node){
if(dep[find(node)]!=-1) return;
dep[find(node)]=1;
for(auto i:edges[find(node)]){
dfs(find(i));
dep[find(node)]=max(dep[find(node)], dep[find(i)]+1);
}
}
void mark(int node){
if(ans[find(node)]!="?") return;
ans[find(node)] = "K";
ans[find(node)] += to_string(dep[find(node)]);
for(auto i:edges[find(node)]){
if(dep[find(i)]==dep[find(node)]-1){
mark(find(i));
}
}
}
void solve(){
int n, m, v; cin >> n >> m >> v;
for(int i=1; i<=m; i++){
dad[i]=i;
ans[i]="?";
dep[i]=-1;
}
vector<string> later;
for(int i=1; i<=v; i++){
string s; cin >> s;
int a=s[0]-'0', b=s[2]-'0';
if(s[1]=='='){
unite(a,b);
}
else later.pb(s);
}
for(auto s:later){
int a=s[0]-'0', b=s[2]-'0';
if(s[1]=='<'){
edges[find(b)].insert(find(a));
}
else edges[find(a)].insert(find(b));
}
for(int i=1; i<=m; i++){
dfs(find(i));
}
for(int i=1; i<=m; i++){
if(dep[find(i)]==n) mark(find(i));
}
for(int i=1; i<=m; i++){
cout << ans[find(i)] << endl;
}
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out","w",stdout);
#endif
ll t=1;
//cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
27228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
234 ms |
32468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
32596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
399 ms |
45436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |