39132023-03-05 12:21:36zsomborDinókcpp17Accepted 100/100370ms27300 KiB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n, m, t, a, b;
vector <vector <int>> g(2e5 + 1);
vector <bool> ent(2e5 + 1, false);
vector <bool> lef(2e5 + 1, false);
vector <int> tp;
vector <int> ans(2e5 + 1, 0);

void get_tp(int x) {
    if (ent[x] && !lef[x]) { cout << "NEM"; exit(0); }
    if (ent[x]) return;
    ent[x] = true;
    for (int i : g[x]) get_tp(i);
    lef[x] = true;
    tp.push_back(x);
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++) g[i].push_back(i + n);
    for (int i = 0; i < m; i++) {
        cin >> t >> a >> b;
        if (t == 1) {
            g[a].push_back(b + n);
            g[b].push_back(a + n);
        }
        if (t == 2) g[a + n].push_back(b);
    }
    for (int i = 1; i <= n; i++) get_tp(i);
    reverse(tp.begin(), tp.end());
    for (int i = 0; i < 2 * n; i++) ans[tp[i]] = i + 1;
    cout << "IGEN\n";
    for (int i = 1; i <= n; i++) cout << ans[i] << " " << ans[i + n] << endl;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted8ms12720 KiB
2Accepted7ms12916 KiB
3Accepted10ms13712 KiB
subtask25/5
4Accepted328ms23160 KiB
5Accepted275ms22236 KiB
6Accepted268ms21736 KiB
subtask315/15
7Accepted8ms13444 KiB
8Accepted8ms13680 KiB
9Accepted8ms13788 KiB
10Accepted7ms13860 KiB
11Accepted7ms14076 KiB
12Accepted7ms14128 KiB
subtask410/10
13Accepted7ms14128 KiB
14Accepted7ms14272 KiB
15Accepted6ms14200 KiB
16Accepted7ms14196 KiB
17Accepted7ms14200 KiB
subtask535/35
18Accepted7ms14460 KiB
19Accepted8ms14524 KiB
20Accepted335ms27300 KiB
21Accepted344ms27244 KiB
22Accepted7ms14980 KiB
23Accepted8ms15056 KiB
24Accepted112ms25296 KiB
subtask635/35
25Accepted335ms25608 KiB
26Accepted296ms25656 KiB
27Accepted321ms25668 KiB
28Accepted326ms25608 KiB
29Accepted112ms24444 KiB
30Accepted298ms25968 KiB
31Accepted347ms25636 KiB
32Accepted119ms24424 KiB
33Accepted112ms25576 KiB
34Accepted370ms25936 KiB
35Accepted115ms23912 KiB