#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];
vi 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[node]!=-1) return;
dep[node]=1;
for(auto i:edges[node]){
dfs(i);
dep[node]=max(dep[node], dep[i]+1);
}
}
void mark(int node){
if(ans[node]!="?") return;
ans[node] = "K";
ans[node] += to_string(dep[node]);
for(auto i:edges[node]){
if(dep[i]==dep[node]-1){
mark(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)].pb(find(a));
}
else edges[find(a)].pb(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();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
21084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
235 ms |
26204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
27180 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
363 ms |
39944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |