#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";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 2ms | 2184 KiB | ||||
3 | Accepted | 4ms | 3268 KiB | ||||
subtask2 | 5/5 | ||||||
4 | Accepted | 93ms | 23568 KiB | ||||
5 | Accepted | 61ms | 22696 KiB | ||||
6 | Accepted | 46ms | 22524 KiB | ||||
subtask3 | 15/15 | ||||||
7 | Accepted | 2ms | 2712 KiB | ||||
8 | Accepted | 2ms | 2944 KiB | ||||
9 | Accepted | 2ms | 3148 KiB | ||||
10 | Accepted | 2ms | 3252 KiB | ||||
11 | Accepted | 2ms | 3352 KiB | ||||
12 | Accepted | 2ms | 3356 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 2ms | 3480 KiB | ||||
14 | Accepted | 2ms | 3556 KiB | ||||
15 | Accepted | 2ms | 3556 KiB | ||||
16 | Accepted | 2ms | 3748 KiB | ||||
17 | Accepted | 2ms | 3824 KiB | ||||
subtask5 | 35/35 | ||||||
18 | Accepted | 2ms | 3812 KiB | ||||
19 | Accepted | 3ms | 4160 KiB | ||||
20 | Accepted | 93ms | 27352 KiB | ||||
21 | Accepted | 82ms | 27600 KiB | ||||
22 | Accepted | 2ms | 4572 KiB | ||||
23 | Accepted | 2ms | 4696 KiB | ||||
24 | Accepted | 68ms | 27468 KiB | ||||
subtask6 | 35/35 | ||||||
25 | Accepted | 86ms | 25508 KiB | ||||
26 | Accepted | 87ms | 25516 KiB | ||||
27 | Accepted | 104ms | 25692 KiB | ||||
28 | Accepted | 92ms | 25668 KiB | ||||
29 | Accepted | 68ms | 26500 KiB | ||||
30 | Accepted | 96ms | 26036 KiB | ||||
31 | Accepted | 94ms | 25644 KiB | ||||
32 | Accepted | 67ms | 26308 KiB | ||||
33 | Accepted | 65ms | 26960 KiB | ||||
34 | Accepted | 98ms | 25852 KiB | ||||
35 | Accepted | 75ms | 25272 KiB |