This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MX=300005;
int n,m,v;
int comp[MX];
vector<int>g[MX];
void compose(int v,int c){
comp[v]=c;
for(int i:g[v])
if(!comp[i])
compose(i,c);
}
int d[MX],r[MX];
vector<int>gd[MX],gr[MX];
int dfsx(int v){
if(d[v]) return d[v];
for(int i:gd[v])
d[v]=max(d[v],dfsx(i));
return ++d[v];
}
int dfsy(int v){
if(r[v]) return r[v];
for(int i:gr[v])
r[v]=max(r[v],dfsy(i));
return ++r[v];
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m>>v;
vector<pair<int,int>>edg;
while(v--){
int a,b;char c;
cin>>a>>c>>b;
if(c=='<')edg.push_back({a,b});
else{
g[a].push_back(b);g[b].push_back(a);
}
}
for(int i=1;i<=m;i++)
if(!comp[i])
compose(i,i);
for(auto i:edg){
int x=i.first,y=i.second;
gd[comp[x]].push_back(comp[y]);
gr[comp[y]].push_back(comp[x]);
}
for(int i=1;i<=m;i++){
dfsx(comp[i]);dfsy(comp[i]);
}
for(int i=1;i<=m;i++){
if(d[comp[i]]+r[comp[i]]==n+1)cout<<"K"<<r[comp[i]]<<endl;
else cout<<"?"<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |