#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, wc, 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<bool> w(N + 1);
for(i = 1; i <= N; i++)
{
nodes[i].after = nodes[i].before = -1;
w[i] = false;
}
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 = wc = 0;
while(true)
{
w[ni] = true;
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]])
sames.push_back(nodes[sames[si]].sames[i]);
w[nodes[sames[si]].sames[i]] = true;
}
si++;
}
m += 2 * sames.size();
for(i = 0; i < sames.size(); i++)
ivs[sames[i]] = make_pair(i + pm + 1, m - i);
pm = m;
wc += sames.size();
if(nodes[ni].after == -1)
break;
else
ni = nodes[ni].after;
}
if(wc != N)
cout << "NEM" << endl;
else
{
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 | Partially correct | 3ms | 1688 KiB | ||||
2 | Accepted | 3ms | 1848 KiB | ||||
3 | Accepted | 8ms | 3412 KiB | ||||
subtask2 | 0/5 | ||||||
4 | Wrong answer | 129ms | 33248 KiB | ||||
5 | Wrong answer | 64ms | 23996 KiB | ||||
6 | Wrong answer | 35ms | 18736 KiB | ||||
subtask3 | 0/15 | ||||||
7 | Wrong answer | 3ms | 2892 KiB | ||||
8 | Accepted | 3ms | 3096 KiB | ||||
9 | Wrong answer | 2ms | 3212 KiB | ||||
10 | Partially correct | 3ms | 3332 KiB | ||||
11 | Partially correct | 3ms | 3444 KiB | ||||
12 | Wrong answer | 2ms | 3536 KiB | ||||
subtask4 | 0/10 | ||||||
13 | Wrong answer | 3ms | 3660 KiB | ||||
14 | Partially correct | 2ms | 3744 KiB | ||||
15 | Accepted | 3ms | 3988 KiB | ||||
16 | Accepted | 2ms | 4072 KiB | ||||
17 | Wrong answer | 2ms | 4072 KiB | ||||
subtask5 | 0/35 | ||||||
18 | Wrong answer | 2ms | 4076 KiB | ||||
19 | Wrong answer | 3ms | 4416 KiB | ||||
20 | Wrong answer | 101ms | 25892 KiB | ||||
21 | Wrong answer | 101ms | 25828 KiB | ||||
22 | Wrong answer | 3ms | 4196 KiB | ||||
23 | Accepted | 3ms | 4280 KiB | ||||
24 | Accepted | 101ms | 25948 KiB | ||||
subtask6 | 0/35 | ||||||
25 | Wrong answer | 123ms | 32188 KiB | ||||
26 | Wrong answer | 118ms | 32436 KiB | ||||
27 | Wrong answer | 119ms | 32228 KiB | ||||
28 | Wrong answer | 119ms | 32272 KiB | ||||
29 | Accepted | 114ms | 30232 KiB | ||||
30 | Wrong answer | 119ms | 31968 KiB | ||||
31 | Wrong answer | 120ms | 32212 KiB | ||||
32 | Accepted | 112ms | 30232 KiB | ||||
33 | Accepted | 103ms | 28016 KiB | ||||
34 | Wrong answer | 116ms | 33008 KiB | ||||
35 | Accepted | 136ms | 35240 KiB |