Code Submission Evaluation System Login

CSES - HIIT Open 2017

HIIT Open 2017

Contest start:2017-05-27 11:00:00
Contest end:2017-05-27 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard


History
2017-05-27 15:54:38
Task:Factory
Sender:oispa opiskelupaikka tefyllä ;...;
Submission time:2017-05-27 15:54:38
Status:READY
Result:WRONG ANSWER

Show test data

Code

#include <bits/stdc++.h>

using namespace std;
vector<int> v[505];
int c[505];
int main(){
    
    int n, m; cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int a, b; cin >> a >> b;
        v[a].push_back(b);
        c[b]++;
    }
    priority_queue<pair<int, int>> q;
    for(int i = 1; i <= n; ++i){
        if(c[i] == 0)
            q.push({v[i].size(), i});
    }
    int days = 0;
    while(!q.empty()){
        pair<int, int> a = q.top();
        q.pop();
        if(q.size() > 0){
            pair<int, int> b = q.top();
            q.pop();
            for(auto f: v[b.second]){
            c[f]--;
            if(c[f] == 0)
                q.push({v[f].size(), f});
        }
        }
        for(auto f: v[a.second]){
            c[f]--;
            if(c[f] == 0)
                q.push({v[f].size(), f});
        }
        days++;
        
    }
    cout << days << endl;
    return 0;
}