#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <set>
using namespace std;
using ll = long long int;
set<int> g[200100];
int l[100100], r[100100];
int val[200100];
int color[200100];
deque<int> q;
int ido = 0;
bool topsort(int node) {
color[node] = 1;
bool ans = true;
for (auto i : g[node]) {
if (color[i] == 1) {
cout << "NEM" << endl;
exit(0);
return false;
}
else if (color[i] == 0) {
ans &= topsort(i);
}
}
q.push_front(node);
color[node] = 2;
return ans;
}
vector<pair<int, int>> kettes;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
int cnt = 1;
for (int i = 1; i <= n; ++i) {
l[i] = cnt++;
r[i] = cnt++;
g[l[i]].emplace(r[i]);
}
while (m--) {
int t, a, b;
cin >> t >> a >> b;
if (t == 1) {
g[l[b]].emplace(r[a]); //ok
g[l[a]].emplace(r[b]);
}
if (t == 2) {
g[r[a]].emplace(l[b]);
}
}
/*for (int i = 1; i <= 2 * n; ++i) {
for (auto j : g[i]) {
cerr << j << " ";
}
cerr << endl;
}*/
for (int i = 1; i <= 2 * n; ++i) {
color[i] = 0;
}
q.clear();
bool ok = true;
for (int i = 1; i <= 2 * n; ++i) {
if (!color[i]) ok &= topsort(i);
}
if (ok) {
for (int i = 0; i < 2 * n; ++i) {
val[q[i]] = i + 1;
}
cout << "IGEN\n";
for (int i = 1; i <= n; ++i) {
cout << val[l[i]] << " " << val[r[i]] << "\n";
}
return 0;
}
return 0;
}
Részfeladat | Összpont | Teszt | Verdikt | Idő | Memória | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Elfogadva | 8ms | 20700 KiB | ||||
2 | Elfogadva | 10ms | 20980 KiB | ||||
3 | Elfogadva | 14ms | 22632 KiB | ||||
subtask2 | 5/5 | ||||||
4 | Elfogadva | 155ms | 57376 KiB | ||||
5 | Elfogadva | 93ms | 48876 KiB | ||||
6 | Elfogadva | 75ms | 44744 KiB | ||||
subtask3 | 15/15 | ||||||
7 | Elfogadva | 9ms | 24560 KiB | ||||
8 | Elfogadva | 10ms | 24644 KiB | ||||
9 | Elfogadva | 10ms | 24608 KiB | ||||
10 | Elfogadva | 9ms | 24876 KiB | ||||
11 | Elfogadva | 8ms | 24952 KiB | ||||
12 | Elfogadva | 8ms | 25320 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Elfogadva | 8ms | 25248 KiB | ||||
14 | Elfogadva | 8ms | 25160 KiB | ||||
15 | Elfogadva | 8ms | 25432 KiB | ||||
16 | Elfogadva | 8ms | 25540 KiB | ||||
17 | Elfogadva | 8ms | 25648 KiB | ||||
subtask5 | 35/35 | ||||||
18 | Elfogadva | 10ms | 25660 KiB | ||||
19 | Elfogadva | 10ms | 25764 KiB | ||||
20 | Elfogadva | 111ms | 52164 KiB | ||||
21 | Elfogadva | 108ms | 53504 KiB | ||||
22 | Elfogadva | 8ms | 28324 KiB | ||||
23 | Elfogadva | 9ms | 28548 KiB | ||||
24 | Elfogadva | 78ms | 51824 KiB | ||||
subtask6 | 35/35 | ||||||
25 | Elfogadva | 171ms | 62764 KiB | ||||
26 | Elfogadva | 140ms | 64152 KiB | ||||
27 | Elfogadva | 150ms | 65384 KiB | ||||
28 | Elfogadva | 142ms | 66840 KiB | ||||
29 | Elfogadva | 92ms | 63420 KiB | ||||
30 | Elfogadva | 137ms | 68932 KiB | ||||
31 | Elfogadva | 137ms | 70808 KiB | ||||
32 | Elfogadva | 89ms | 67480 KiB | ||||
33 | Elfogadva | 75ms | 66064 KiB | ||||
34 | Elfogadva | 152ms | 75448 KiB | ||||
35 | Elfogadva | 119ms | 76280 KiB |