#include <vector>
#include <queue>
#include <iostream>
using ll = long long;
using namespace std;
int main()
{
ll i, j, c, e, t, a, b, N, M;
cin >> N >> M;
vector<vector<ll>> ss(M);
for(i = 0; i < M; i++)
{
cin >> t >> a >> b;
ss[i] = vector<ll> { t, a, b };
}
vector<vector<ll>> g(2 * N + 1);
vector<ll> ine(2 * N + 1, 0);
for(i = 1; i <= N; i++)
{
g[i].push_back(i + N);
ine[i + N]++;
}
for(i = 0; i < M; i++)
{
switch(ss[i][0])
{
case 1:
g[ss[i][1]].push_back(ss[i][2] + N);
ine[ss[i][2] + N]++;
g[ss[i][2]].push_back(ss[i][1] + N);
ine[ss[i][1] + N]++;
break;
case 2:
g[ss[i][1] + N].push_back(ss[i][2]);
ine[ss[i][2]]++;
break;
default:
break;
}
}
c = 1;
vector<ll> ans(2 * N + 1, 0);
queue<ll> q;
for(i = 1; i <= N; i++)
{
if(!ine[i])
q.push(i);
}
while(q.size())
{
e = q.front();
q.pop();
ans[e] = c++;
for(auto x : g[e])
{
if(!--ine[x])
q.push(x);
}
}
for(i = 1; i <= 2 * N; i++)
{
if(!ans[i])
{
cout << "NEM" << endl;
return 0;
}
}
cout << "IGEN" << endl;
for(i = 1; i <= N; i++)
cout << ans[i] << ' ' << ans[i + N] << endl;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1812 KiB | ||||
2 | Accepted | 3ms | 2056 KiB | ||||
3 | Accepted | 8ms | 4260 KiB | ||||
subtask2 | 5/5 | ||||||
4 | Accepted | 344ms | 41336 KiB | ||||
5 | Accepted | 200ms | 33700 KiB | ||||
6 | Accepted | 193ms | 30156 KiB | ||||
subtask3 | 15/15 | ||||||
7 | Accepted | 3ms | 2908 KiB | ||||
8 | Accepted | 3ms | 3128 KiB | ||||
9 | Accepted | 3ms | 3512 KiB | ||||
10 | Accepted | 2ms | 3412 KiB | ||||
11 | Accepted | 2ms | 3416 KiB | ||||
12 | Accepted | 3ms | 3660 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 3ms | 3872 KiB | ||||
14 | Accepted | 3ms | 4080 KiB | ||||
15 | Accepted | 2ms | 4048 KiB | ||||
16 | Accepted | 3ms | 4184 KiB | ||||
17 | Accepted | 3ms | 4260 KiB | ||||
subtask5 | 35/35 | ||||||
18 | Accepted | 3ms | 4276 KiB | ||||
19 | Accepted | 4ms | 4536 KiB | ||||
20 | Accepted | 300ms | 42008 KiB | ||||
21 | Accepted | 245ms | 42140 KiB | ||||
22 | Accepted | 3ms | 4352 KiB | ||||
23 | Accepted | 4ms | 4776 KiB | ||||
24 | Accepted | 136ms | 42504 KiB | ||||
subtask6 | 35/35 | ||||||
25 | Accepted | 272ms | 42520 KiB | ||||
26 | Accepted | 273ms | 42268 KiB | ||||
27 | Accepted | 308ms | 42272 KiB | ||||
28 | Accepted | 287ms | 42268 KiB | ||||
29 | Accepted | 141ms | 41668 KiB | ||||
30 | Accepted | 264ms | 42188 KiB | ||||
31 | Accepted | 402ms | 42400 KiB | ||||
32 | Accepted | 150ms | 41824 KiB | ||||
33 | Accepted | 136ms | 41884 KiB | ||||
34 | Accepted | 257ms | 42532 KiB | ||||
35 | Accepted | 137ms | 43444 KiB |