#include <vector>
#include <queue>
#include <unordered_set>
#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<unordered_set<ll>> g(2 * N + 1);
for(i = 0; i < M; i++)
{
switch(ss[i][0])
{
case 1:
g[ss[i][1]].insert(ss[i][2] + N);
g[ss[i][2]].insert(ss[i][1] + N);
break;
case 2:
g[ss[i][1] + N].insert(ss[i][2]);
break;
default:
break;
}
}
for(i = 1; i <= N; i++)
g[i].insert(i + N);
vector<ll> ine(2 * N + 1, 0);
for(i = 1; i <= 2 * N; i++)
{
for(auto x : g[i])
ine[x]++;
}
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 | 1684 KiB | ||||
2 | Accepted | 3ms | 1928 KiB | ||||
3 | Accepted | 10ms | 6248 KiB | ||||
subtask2 | 0/5 | ||||||
4 | Time limit exceeded | 544ms | 83552 KiB | ||||
5 | Accepted | 300ms | 72232 KiB | ||||
6 | Accepted | 237ms | 66424 KiB | ||||
subtask3 | 15/15 | ||||||
7 | Accepted | 3ms | 2908 KiB | ||||
8 | Accepted | 3ms | 2972 KiB | ||||
9 | Accepted | 3ms | 3216 KiB | ||||
10 | Accepted | 2ms | 3328 KiB | ||||
11 | Accepted | 3ms | 3328 KiB | ||||
12 | Accepted | 3ms | 3448 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 3ms | 3720 KiB | ||||
14 | Accepted | 3ms | 3492 KiB | ||||
15 | Accepted | 3ms | 3496 KiB | ||||
16 | Accepted | 3ms | 3572 KiB | ||||
17 | Accepted | 3ms | 3656 KiB | ||||
subtask5 | 35/35 | ||||||
18 | Accepted | 3ms | 3648 KiB | ||||
19 | Accepted | 4ms | 4444 KiB | ||||
20 | Accepted | 388ms | 92144 KiB | ||||
21 | Accepted | 485ms | 92356 KiB | ||||
22 | Accepted | 3ms | 4292 KiB | ||||
23 | Accepted | 4ms | 5216 KiB | ||||
24 | Accepted | 229ms | 92148 KiB | ||||
subtask6 | 0/35 | ||||||
25 | Accepted | 460ms | 88116 KiB | ||||
26 | Time limit exceeded | 544ms | 88120 KiB | ||||
27 | Accepted | 402ms | 88364 KiB | ||||
28 | Accepted | 490ms | 88328 KiB | ||||
29 | Accepted | 286ms | 90524 KiB | ||||
30 | Accepted | 433ms | 89560 KiB | ||||
31 | Accepted | 483ms | 88704 KiB | ||||
32 | Accepted | 233ms | 90780 KiB | ||||
33 | Accepted | 215ms | 92172 KiB | ||||
34 | Accepted | 370ms | 89700 KiB | ||||
35 | Accepted | 239ms | 87056 KiB |