#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);
vector<ll> ine(2 * N + 1, 0);
for(i = 0; i < M; i++)
{
switch(ss[i][0])
{
case 1:
g[ss[i][1]].insert(ss[i][2] + N);
ine[ss[i][2] + N]++;
g[ss[i][2]].insert(ss[i][1] + N);
ine[ss[i][1] + N]++;
break;
case 2:
g[ss[i][1] + N].insert(ss[i][2]);
ine[ss[i][2]]++;
break;
default:
break;
}
}
for(i = 1; i <= N; i++)
{
g[i].insert(i + N);
ine[i + N]++;
}
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 | 1808 KiB | ||||
2 | Accepted | 3ms | 2060 KiB | ||||
3 | Accepted | 10ms | 6324 KiB | ||||
subtask2 | 0/5 | ||||||
4 | Wrong answer | 277ms | 83448 KiB | ||||
5 | Accepted | 354ms | 72176 KiB | ||||
6 | Accepted | 280ms | 66372 KiB | ||||
subtask3 | 0/15 | ||||||
7 | Accepted | 3ms | 2724 KiB | ||||
8 | Accepted | 3ms | 2852 KiB | ||||
9 | Accepted | 3ms | 2936 KiB | ||||
10 | Wrong answer | 3ms | 3064 KiB | ||||
11 | Wrong answer | 3ms | 3144 KiB | ||||
12 | Accepted | 3ms | 3176 KiB | ||||
subtask4 | 0/10 | ||||||
13 | Wrong answer | 3ms | 3264 KiB | ||||
14 | Wrong answer | 3ms | 3252 KiB | ||||
15 | Accepted | 3ms | 3252 KiB | ||||
16 | Accepted | 3ms | 3384 KiB | ||||
17 | Wrong answer | 3ms | 3600 KiB | ||||
subtask5 | 0/35 | ||||||
18 | Accepted | 3ms | 3728 KiB | ||||
19 | Wrong answer | 3ms | 4380 KiB | ||||
20 | Wrong answer | 223ms | 91580 KiB | ||||
21 | Wrong answer | 228ms | 91992 KiB | ||||
22 | Accepted | 3ms | 3924 KiB | ||||
23 | Accepted | 4ms | 4704 KiB | ||||
24 | Accepted | 223ms | 91792 KiB | ||||
subtask6 | 0/35 | ||||||
25 | Wrong answer | 275ms | 87984 KiB | ||||
26 | Wrong answer | 230ms | 87884 KiB | ||||
27 | Wrong answer | 279ms | 87972 KiB | ||||
28 | Wrong answer | 228ms | 88096 KiB | ||||
29 | Accepted | 224ms | 90424 KiB | ||||
30 | Accepted | 409ms | 89440 KiB | ||||
31 | Time limit exceeded | 519ms | 88660 KiB | ||||
32 | Accepted | 231ms | 90488 KiB | ||||
33 | Accepted | 206ms | 91920 KiB | ||||
34 | Accepted | 432ms | 89320 KiB | ||||
35 | Accepted | 316ms | 86576 KiB |