20852022-12-16 22:13:20TomaSajtDinókcpp17Accepted 100/100104ms27600 KiB
#include <bits/stdc++.h>
#define speed ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int main() {
    speed;
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(2 * n);
    vector<int> deps(2 * n), pos(2 * n);
    auto makeEdge = [&](int u, int v) { g[u].push_back(v); deps[v]++; };
    for (int i = 0; i < n; i++) makeEdge(2 * i, 2 * i + 1);
    while (m--) {
        int t, a, b;
        cin >> t >> a >> b; --a, --b;
        if (t == 1) makeEdge(2 * b, 2 * a + 1), makeEdge(2 * a, 2 * b + 1);
        else makeEdge(2 * a + 1, 2 * b);
    }
    queue<int> q;
    for (int i = 0; i < n; i++) {
        if (deps[2 * i] == 0) q.push(2 * i);
    }
    int cnt = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        pos[u] = ++cnt;
        for (int v : g[u]) {
            if (--deps[v] == 0) q.push(v);
        }
    }
    if (cnt == 2 * n) {
        cout << "IGEN";
        for (int i = 0; i < n; i++) cout << '\n' << pos[2 * i] << ' ' << pos[2 * i + 1];
    }
    else cout << "NEM";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted2ms2184 KiB
3Accepted4ms3268 KiB
subtask25/5
4Accepted93ms23568 KiB
5Accepted61ms22696 KiB
6Accepted46ms22524 KiB
subtask315/15
7Accepted2ms2712 KiB
8Accepted2ms2944 KiB
9Accepted2ms3148 KiB
10Accepted2ms3252 KiB
11Accepted2ms3352 KiB
12Accepted2ms3356 KiB
subtask410/10
13Accepted2ms3480 KiB
14Accepted2ms3556 KiB
15Accepted2ms3556 KiB
16Accepted2ms3748 KiB
17Accepted2ms3824 KiB
subtask535/35
18Accepted2ms3812 KiB
19Accepted3ms4160 KiB
20Accepted93ms27352 KiB
21Accepted82ms27600 KiB
22Accepted2ms4572 KiB
23Accepted2ms4696 KiB
24Accepted68ms27468 KiB
subtask635/35
25Accepted86ms25508 KiB
26Accepted87ms25516 KiB
27Accepted104ms25692 KiB
28Accepted92ms25668 KiB
29Accepted68ms26500 KiB
30Accepted96ms26036 KiB
31Accepted94ms25644 KiB
32Accepted67ms26308 KiB
33Accepted65ms26960 KiB
34Accepted98ms25852 KiB
35Accepted75ms25272 KiB