Submission #95355

# Submission time Handle Problem Language Result Execution time Memory
95355 2019-01-30T15:58:49 Z dalgerok KOVANICE (COI15_kovanice) C++14
0 / 100
873 ms 525312 KB
#include<bits/stdc++.h>
using namespace std;



const int N = 3e5 + 5;



int n, m, k, p[N], dp1[N], dp2[N], used[N], sz;
vector < int > g[N], gr[N], q[N];
vector < pair < int, int > > e;

void dfs(int v){
    used[v] = sz;
    for(int to : q[v]){
        if(!used[to]){
            dfs(to);
        }
    }
}

int dfs1(int v){
    if(dp1[v]){
        return dp1[v];
    }
    for(int to : g[v]){
        dp1[v] = max(dp1[v], dfs1(to));
    }
    dp1[v] += 1;
    return dp1[v];
}

int dfs2(int v){
    if(dp2[v]){
        return dp2[v];
    }
    for(int to : gr[v]){
        dp2[v] = max(dp2[v], dfs2(to));
    }
    dp2[v] += 1;
    return dp2[v];
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m >> k;
    for(int i = 1; i <= k; i++){
        int x, y;
        char c;
        cin >> x >> c >> y;
        if(c == '<'){
            e.push_back(make_pair(x, y));
        }
        else{
            q[x].push_back(y);
            q[y].push_back(x);
        }
    }
    for(int i = 1; i <= n; i++){
        if(!used[i]){
            sz += 1;
            dfs(i);
        }
    }
    for(auto it : e){
        g[used[it.second]].push_back(used[it.first]);
        gr[used[it.first]].push_back(used[it.second]);
    }
    for(int i = 1; i <= m; i++){
        dfs1(used[i]);
        dfs2(used[i]);
    }
    for(int i = 1; i <= m; i++){
        if(dp1[used[i]] + dp2[used[i]] - 1 == n){
            cout << "K" << dp1[used[i]] << "\n";
        }
        else{
            cout << "?\n";
        }
    }
}

# Verdict Execution time Memory Grader output
1 Runtime error 873 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 507 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 400 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 600 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -