#include <vector>
#include <iostream>
using ll = long long;
using namespace std;
struct Node
{
ll after;
ll before;
vector<ll> sames;
};
int main()
{
ll i, a, b, c, m, pm, ni, si, N, M;
cin >> N >> M;
vector<vector<ll>> ss(M);
for(i = 0; i < M; i++)
{
cin >> a >> b >> c;
ss[i] = vector<ll> { a, b, c };
}
vector<Node> nodes(N + 1);
vector<pair<ll, ll>> ivs(N + 1);
vector<ll> w(N + 1);
for(i = 1; i <= N; i++)
{
nodes[i].after = nodes[i].before = -1;
w[i] = 0;
}
for(i = 0; i < M; i++)
{
switch(ss[i][0])
{
case 1:
nodes[ss[i][1]].sames.push_back(ss[i][2]);
nodes[ss[i][2]].sames.push_back(ss[i][1]);
break;
case 2:
nodes[ss[i][1]].after = ss[i][2];
nodes[ss[i][2]].before = ss[i][1];
break;
default:
break;
}
}
for(i = 1; i <= N; i++)
{
if(nodes[i].before == -1)
break;
}
ni = i;
pm = 0;
while(true)
{
w[ni]++;
vector<ll> sames { ni };
si = 0;
while(si < sames.size())
{
for(i = 0; i < nodes[sames[si]].sames.size(); i++)
{
if(w[nodes[sames[si]].sames[i]])
continue;
sames.push_back(nodes[sames[si]].sames[i]);
w[nodes[sames[si]].sames[i]]++;
}
si++;
}
m = pm + 2 * sames.size();
for(i = 0; i < sames.size(); i++)
ivs[sames[i]] = make_pair(i + pm + 1, m - i);
pm = m;
if(nodes[ni].after == -1)
break;
else
ni = nodes[ni].after;
}
for(i = 1; i <= N; i++)
{
if(w[i] != 1)
{
cout << "NEM" << endl;
return 0;
}
}
cout << "IGEN" << endl;
for(i = 1; i <= N; i++)
cout << ivs[i].first << ' ' << ivs[i].second << endl;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1812 KiB | ||||
2 | Accepted | 3ms | 2000 KiB | ||||
3 | Accepted | 8ms | 3568 KiB | ||||
subtask2 | 0/5 | ||||||
4 | Wrong answer | 136ms | 34828 KiB | ||||
5 | Wrong answer | 70ms | 25160 KiB | ||||
6 | Wrong answer | 39ms | 20132 KiB | ||||
subtask3 | 0/15 | ||||||
7 | Accepted | 3ms | 2676 KiB | ||||
8 | Accepted | 3ms | 2916 KiB | ||||
9 | Wrong answer | 3ms | 2904 KiB | ||||
10 | Partially correct | 3ms | 3176 KiB | ||||
11 | Partially correct | 3ms | 3336 KiB | ||||
12 | Wrong answer | 3ms | 3504 KiB | ||||
subtask4 | 0/10 | ||||||
13 | Wrong answer | 3ms | 3712 KiB | ||||
14 | Partially correct | 3ms | 3832 KiB | ||||
15 | Accepted | 3ms | 3772 KiB | ||||
16 | Accepted | 3ms | 3888 KiB | ||||
17 | Wrong answer | 3ms | 3772 KiB | ||||
subtask5 | 0/35 | ||||||
18 | Wrong answer | 3ms | 3776 KiB | ||||
19 | Wrong answer | 3ms | 3844 KiB | ||||
20 | Wrong answer | 101ms | 27348 KiB | ||||
21 | Wrong answer | 101ms | 27560 KiB | ||||
22 | Wrong answer | 3ms | 4208 KiB | ||||
23 | Accepted | 3ms | 4308 KiB | ||||
24 | Accepted | 101ms | 27516 KiB | ||||
subtask6 | 0/35 | ||||||
25 | Wrong answer | 119ms | 33796 KiB | ||||
26 | Wrong answer | 123ms | 33920 KiB | ||||
27 | Wrong answer | 118ms | 33976 KiB | ||||
28 | Wrong answer | 115ms | 33848 KiB | ||||
29 | Accepted | 112ms | 31868 KiB | ||||
30 | Wrong answer | 116ms | 33636 KiB | ||||
31 | Wrong answer | 123ms | 33828 KiB | ||||
32 | Accepted | 111ms | 31872 KiB | ||||
33 | Accepted | 104ms | 29480 KiB | ||||
34 | Wrong answer | 115ms | 34164 KiB | ||||
35 | Accepted | 123ms | 36576 KiB |