51972023-04-21 22:02:59ZsofiaKeresztelyDinókcpp14Time limit exceeded 35/100601ms35988 KiB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g, g2, comp;
vector<int> ind, tops, op, c;
vector<bool> inq;
int n, last = 1, cur = 0;

void dfs(int v){
    c[v] = cur;
    comp[cur].push_back(v);
    for (int x : g2[v]){
        if (c[x] < 0){
            dfs(x);
        }
    }
}

void bfs(){
    queue<int> q;
    for (int i=1; i<=n; i++){
        if (!ind[i]){
            q.push(i);
        }
    }
    while (!q.empty()){
        int v = q.front();
        q.pop();
        if (op[v]) continue;
        for (int x : comp[c[v]]){
            if (x == v) continue;
            if (!inq[x]){
                inq[v] = 1;
            }
        }
        if (!inq[v]){
            for (int x : comp[c[v]]){
                op[x] = last;
                for (int y : g[x]){
                    ind[y]--;
                    if (!ind[y]) q.push(y);
                }
            }
            last += 2;
        }
    }
}

int main()
{
    int m;
    cin >> n >> m;
    g.resize(n+1);
    g2.resize(n+1);
    comp.resize(n+1);
    inq.assign(n+1, 0);
    ind.assign(n+1, 0);
    c.assign(n+1, -1);
    op.assign(n+1, 0);
    while (m--){
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 2){
            g[a].push_back(b);
            ind[b]++;
        }
        else{
            g2[a].push_back(b);
            g2[b].push_back(a);
        }
    }
    for (int i=1; i<=n; i++){
        if (c[i] < 0){
            comp.push_back({});
            dfs(i);
            cur++;
        }
    }
    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
1Accepted3ms1692 KiB
2Accepted3ms1844 KiB
3Accepted8ms3444 KiB
subtask20/5
4Time limit exceeded601ms15492 KiB
5Time limit exceeded540ms15324 KiB
6Accepted78ms30520 KiB
subtask30/15
7Accepted3ms2844 KiB
8Accepted3ms3092 KiB
9Accepted3ms3284 KiB
10Wrong answer3ms3456 KiB
11Wrong answer3ms3828 KiB
12Accepted2ms3716 KiB
subtask40/10
13Accepted3ms3952 KiB
14Wrong answer2ms4016 KiB
15Accepted3ms4016 KiB
16Accepted3ms4032 KiB
17Wrong answer2ms4028 KiB
subtask535/35
18Accepted3ms3980 KiB
19Accepted3ms4344 KiB
20Accepted166ms35820 KiB
21Accepted158ms35892 KiB
22Accepted3ms4152 KiB
23Accepted4ms4540 KiB
24Accepted136ms35988 KiB
subtask60/35
25Time limit exceeded583ms17660 KiB
26Time limit exceeded566ms17724 KiB
27Time limit exceeded574ms17740 KiB
28Time limit exceeded569ms17752 KiB
29Accepted178ms33244 KiB
30Time limit exceeded564ms18112 KiB
31Time limit exceeded551ms18048 KiB
32Accepted180ms33984 KiB
33Accepted134ms35580 KiB
34Time limit exceeded583ms17928 KiB
35Time limit exceeded579ms17804 KiB