101612024-03-28 21:27:09111Dinókcpp17Accepted 100/100103ms52128 KiB
#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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms1992 KiB
3Accepted6ms3592 KiB
subtask25/5
4Accepted97ms30244 KiB
5Accepted75ms28912 KiB
6Accepted48ms28040 KiB
subtask315/15
7Accepted3ms5468 KiB
8Accepted3ms5552 KiB
9Accepted3ms5680 KiB
10Accepted3ms5896 KiB
11Accepted3ms5984 KiB
12Accepted3ms6120 KiB
subtask410/10
13Accepted3ms6236 KiB
14Accepted3ms6216 KiB
15Accepted3ms6436 KiB
16Accepted3ms6432 KiB
17Accepted3ms6532 KiB
subtask535/35
18Accepted3ms6552 KiB
19Accepted3ms7172 KiB
20Accepted92ms34388 KiB
21Accepted93ms35644 KiB
22Accepted3ms9556 KiB
23Accepted3ms9716 KiB
24Accepted75ms36912 KiB
subtask635/35
25Accepted97ms37928 KiB
26Accepted97ms39268 KiB
27Accepted97ms40612 KiB
28Accepted97ms41932 KiB
29Accepted82ms42724 KiB
30Accepted98ms44532 KiB
31Accepted97ms45960 KiB
32Accepted93ms46896 KiB
33Accepted79ms48664 KiB
34Accepted103ms50208 KiB
35Accepted76ms52128 KiB