51982023-04-21 22:11:08ZsofiaKeresztelyDinókcpp14Time limit exceeded 35/100601ms32232 KiB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g(100001), g2(100001), comp(100001);
vector<int> ind(100001, 0), op(100001, 0), c(100001, 0);
vector<bool> inq(100001, 0);
int n, last = 1, cur = 1;

void dfs(int v){
    c[v] = cur;
    comp[cur].push_back(v);
    for (int x : g2[v]){
        if (!c[x]){
            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()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int m;
    cin >> n >> m;
    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]){
            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
1Accepted10ms17920 KiB
2Accepted8ms18104 KiB
3Accepted10ms18632 KiB
subtask20/5
4Time limit exceeded601ms14688 KiB
5Time limit exceeded573ms13980 KiB
6Accepted52ms26924 KiB
subtask30/15
7Accepted9ms18980 KiB
8Accepted9ms19272 KiB
9Accepted9ms19148 KiB
10Wrong answer9ms19404 KiB
11Wrong answer9ms19444 KiB
12Accepted9ms19512 KiB
subtask40/10
13Accepted9ms19700 KiB
14Wrong answer8ms19968 KiB
15Accepted8ms19832 KiB
16Accepted8ms20088 KiB
17Wrong answer8ms20288 KiB
subtask535/35
18Accepted9ms20484 KiB
19Accepted10ms20672 KiB
20Accepted85ms31600 KiB
21Accepted85ms31564 KiB
22Accepted9ms20564 KiB
23Accepted9ms21016 KiB
24Accepted67ms31408 KiB
subtask60/35
25Time limit exceeded556ms17180 KiB
26Time limit exceeded574ms17380 KiB
27Time limit exceeded561ms17472 KiB
28Time limit exceeded574ms17332 KiB
29Accepted118ms31464 KiB
30Time limit exceeded538ms17356 KiB
31Time limit exceeded574ms17260 KiB
32Accepted104ms31672 KiB
33Accepted78ms32232 KiB
34Time limit exceeded569ms17484 KiB
35Time limit exceeded560ms17612 KiB