Submission #1318461

#TimeUsernameProblemLanguageResultExecution timeMemory
1318461hashimzaderashidKOVANICE (COI15_kovanice)C++20
0 / 100
434 ms41300 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<set<ll>>g(3e5+5);
vector<ll>ch(3e5+5,0);
vector<ll>cl(3e5+5,0);
ll mx = 0;
void dfs(ll k,ll p,ll cn){
    ch[k] = 1;
    cl[k] = cn;
    mx = max(mx,cn);
    for(auto it : g[k]){
        if(!ch[it]){
            if(g[it].find(k) != g[it].end()){
                dfs(it,k,cn);
            }
            else{
                dfs(it,k,cn+1);
            }
        }
    }
}
vector<ll>ch2(3e5+5,0);
void dfs2(ll k,ll cn){
    ch2[k] = 1;
    cl[k] = cn;
    for(auto it : g[k]){
        if(!ch2[it]){
            dfs2(it,cn);
        }
    }
}
int main(){
    ll t,a,b,c,d,e,f;
    char ck;
    cin>>a>>b>>c;
    for(int i =0;i<c;i++){
        cin>>d>>ck>>e;
        if(ck == '<'){
            g[d].insert(e);
        }
        else if(ck == '='){
            g[e].insert(d);
            g[d].insert(e);
        }
        else{
            g[e].insert(d);
        }
    }
    for(int i = 1;i<=b;i++){
        if(!ch[i]){
            mx = 0;
            dfs(i,0,1);
            if(mx < a){
                dfs2(i,-1);
            }
        }
    }
    for(int i = 1;i<=b;i++){
        if(cl[i] == -1){
            cout<<"?"<<endl;
        }
        else{
            cout<<"K"<<cl[i]<<endl;
        }
    }
}
//By Rashid_Hashimzade
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...