#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
vector<vector<int>>g(N*2);
vector<int>c(N*2);
for(int i=0;i<N;i++){
g[i].push_back(N+i);
c[N+i]++;
}
for(int i=0;i<M;i++){
int o,a,b;
cin>>o>>a>>b;
a--,b--;
if(o==1){
g[a].push_back(N+b);
c[N+b]++;
g[b].push_back(N+a);
c[N+a]++;
}
if(o==2){
g[N+a].push_back(b);
c[b]++;
}
}
vector<int>v(N*2);
int t=1;
auto dfs=[&](auto self,int i)->void{
for(int j:g[i]){
if(v[j]){
continue;
}
c[j]--;
if(c[j]==0){
v[j]=t++;
self(self,j);
}
}
};
for(int i=0;i<N*2;i++){
if(v[i]||c[i]){
continue;
}
v[i]=t++;
dfs(dfs,i);
}
if(count(v.begin(),v.end(),0)){
cout<<"NEM"<<'\n';
return 0;
}
cout<<"IGEN"<<'\n';
for(int i=0;i<N;i++){
cout<<v[i]<<' '<<v[N+i]<<'\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 1992 KiB | ||||
3 | Accepted | 6ms | 3592 KiB | ||||
subtask2 | 5/5 | ||||||
4 | Accepted | 97ms | 30244 KiB | ||||
5 | Accepted | 75ms | 28912 KiB | ||||
6 | Accepted | 48ms | 28040 KiB | ||||
subtask3 | 15/15 | ||||||
7 | Accepted | 3ms | 5468 KiB | ||||
8 | Accepted | 3ms | 5552 KiB | ||||
9 | Accepted | 3ms | 5680 KiB | ||||
10 | Accepted | 3ms | 5896 KiB | ||||
11 | Accepted | 3ms | 5984 KiB | ||||
12 | Accepted | 3ms | 6120 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 3ms | 6236 KiB | ||||
14 | Accepted | 3ms | 6216 KiB | ||||
15 | Accepted | 3ms | 6436 KiB | ||||
16 | Accepted | 3ms | 6432 KiB | ||||
17 | Accepted | 3ms | 6532 KiB | ||||
subtask5 | 35/35 | ||||||
18 | Accepted | 3ms | 6552 KiB | ||||
19 | Accepted | 3ms | 7172 KiB | ||||
20 | Accepted | 92ms | 34388 KiB | ||||
21 | Accepted | 93ms | 35644 KiB | ||||
22 | Accepted | 3ms | 9556 KiB | ||||
23 | Accepted | 3ms | 9716 KiB | ||||
24 | Accepted | 75ms | 36912 KiB | ||||
subtask6 | 35/35 | ||||||
25 | Accepted | 97ms | 37928 KiB | ||||
26 | Accepted | 97ms | 39268 KiB | ||||
27 | Accepted | 97ms | 40612 KiB | ||||
28 | Accepted | 97ms | 41932 KiB | ||||
29 | Accepted | 82ms | 42724 KiB | ||||
30 | Accepted | 98ms | 44532 KiB | ||||
31 | Accepted | 97ms | 45960 KiB | ||||
32 | Accepted | 93ms | 46896 KiB | ||||
33 | Accepted | 79ms | 48664 KiB | ||||
34 | Accepted | 103ms | 50208 KiB | ||||
35 | Accepted | 76ms | 52128 KiB |