51962023-04-21 20:39:45ZsofiaKeresztelyDinókcpp14Wrong answer 35/100136ms23020 KiB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g, comp;
vector<int> ind, tops, inq, op;
int n, last = -1;

void bfs(){
    deque<int> q;
    for (int i=1; i<=n; i++){
        if (!ind[i]){
            q.push_front(i);
        }
    }
    while (!q.empty()){
        int v = q.front();
        q.pop_front();
        if (op[v]) continue;
        if (inq[v] > 0) return;
        int ok = 0;
        if (!inq[v]){
            last -= 2;
            ok = comp[v].size();
        }
        else{
            inq[v] = 0;
            for (int x : comp[v]){
                if (inq[x] < 0){
                    inq[v]++;
                }
                else{
                    inq[x]--;
                    if (!inq[x]) ok++;
                }
            }
        }
        if (ok == comp[v].size()){
            last += 2;
            op[v] = last;
            for (int x : comp[v]){
                q.push_front(x);
            }
            for (int x : g[v]){
                ind[x]--;
                if (!ind[x]) q.push_back(x);
            }
        }
    }
}

int main()
{
    int m;
    cin >> n >> m;
    g.resize(n+1);
    comp.resize(n+1);
    inq.assign(n+1, -1);
    ind.assign(n+1, 0);
    op.resize(n+1, 0);
    while (m--){
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 2){
            g[a].push_back(b);
            ind[b]++;
        }
        else{
            comp[a].push_back(b);
            comp[b].push_back(a);
        }
    }
    bfs();
    for (int i=1; i<=n; i++){
        if (!op[i]){
            cout << "NEM";
            return 0;
        }
    }
    cout << "IGEN";
    for (int i=1; i<=n; i++){
        cout << "\n" << op[i] << " " << op[i] + 1;
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1812 KiB
2Accepted3ms1968 KiB
3Accepted7ms3464 KiB
subtask20/5
4Wrong answer109ms20296 KiB
5Wrong answer59ms18796 KiB
6Wrong answer32ms17360 KiB
subtask30/15
7Accepted3ms2896 KiB
8Accepted3ms3108 KiB
9Accepted3ms3224 KiB
10Wrong answer2ms3220 KiB
11Wrong answer3ms3228 KiB
12Accepted3ms3304 KiB
subtask40/10
13Wrong answer3ms3552 KiB
14Wrong answer3ms3592 KiB
15Accepted3ms3676 KiB
16Accepted3ms3804 KiB
17Wrong answer3ms3804 KiB
subtask535/35
18Accepted3ms3808 KiB
19Accepted3ms4064 KiB
20Accepted136ms19996 KiB
21Accepted133ms19996 KiB
22Accepted3ms3968 KiB
23Accepted3ms4036 KiB
24Accepted108ms20128 KiB
subtask60/35
25Wrong answer112ms22544 KiB
26Wrong answer109ms22500 KiB
27Wrong answer111ms22500 KiB
28Wrong answer108ms22496 KiB
29Accepted108ms22756 KiB
30Wrong answer112ms22628 KiB
31Wrong answer108ms22668 KiB
32Accepted108ms22756 KiB
33Accepted107ms21692 KiB
34Wrong answer111ms23020 KiB
35Accepted108ms22500 KiB