102932024-03-30 10:42:22111Pletykálkodáscpp17Wrong answer 0/10057ms11844 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+1);
	vector<pair<int,int>>e;
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
		e.emplace_back(a,b);
	}
	vector<tuple<int,int,int,int>>c;
	for(int i=1;i<=N;i++){
		vector<int>v(N+1);
		v[i]=-1;
		for(int j:g[i]){
			v[j]=-1;
		}
		for(int j:g[i]){
			for(int k:g[j]){
				if(v[k]<0){
					continue;
				}
				if(v[k]>0){
					c.emplace_back(i,k,j,v[k]);
					continue;
				}
				v[k]=j;
			}
		}
	}
	for(auto[a,b,aa,bb]:c){
		vector<int>v(N+1,-1);
		vector<vector<pair<int,int>>>w(2);
		auto dfs=[&](auto self,int i)->void{
			for(int j:g[i]){
				if(v[j]!=-1){
					continue;
				}
				v[j]=v[i];
				self(self,j);
				w[v[i]].emplace_back(i,j);
			}
		};
		v[a]=0;
		v[b]=1;
		v[aa]=0;
		v[bb]=1;
		dfs(dfs,aa);
		dfs(dfs,bb);
		if(count(v.begin(),v.end(),-1)==1){
			vector<pair<int,int>>s;
			for(auto[a,b]:w[0]){
				s.emplace_back(a,b);
			}
			for(auto[a,b]:w[1]){
				s.emplace_back(a,b);
			}
			s.emplace_back(a,aa);
			s.emplace_back(b,bb);
			s.emplace_back(a,b);
			s.emplace_back(aa,bb);
			reverse(w[0].begin(),w[0].end());
			reverse(w[1].begin(),w[1].end());
			for(auto[a,b]:w[0]){
				s.emplace_back(a,b);
			}
			for(auto[a,b]:w[1]){
				s.emplace_back(a,b);
			}
			vector<bitset<1501>>v(N+1);
			for(int i=1;i<=N;i++)v[i][i]=1;
			for(auto[a,b]:s){
				v[a]=v[b]=v[a]|v[b];
			}
			int k=1;
			while(k<=N&&v[k].count()==N)k++;
			if(k<=N){
				exit(1);
			}
			cout<<s.size()<<'\n';
			for(auto[a,b]:s){
				cout<<a<<' '<<b<<'\n';
			}
			return 0;
		}
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1700 KiB
2Wrong answer3ms1936 KiB
3Wrong answer4ms2952 KiB
subtask20/9
4Wrong answer3ms2360 KiB
5Wrong answer3ms2564 KiB
6Wrong answer3ms2736 KiB
subtask30/13
7Wrong answer14ms4120 KiB
8Wrong answer19ms4080 KiB
9Wrong answer19ms4232 KiB
subtask40/16
10Wrong answer14ms5212 KiB
11Wrong answer16ms5420 KiB
12Wrong answer14ms5520 KiB
subtask50/25
13Wrong answer3ms3956 KiB
14Wrong answer3ms4268 KiB
15Wrong answer3ms4192 KiB
16Wrong answer3ms4084 KiB
17Wrong answer3ms4064 KiB
18Wrong answer3ms4272 KiB
19Wrong answer3ms4560 KiB
subtask60/13
20Wrong answer4ms5780 KiB
21Wrong answer9ms5068 KiB
22Wrong answer4ms5776 KiB
23Wrong answer8ms5720 KiB
24Wrong answer6ms5420 KiB
25Wrong answer4ms5212 KiB
26Wrong answer7ms6096 KiB
subtask70/24
27Runtime error26ms11844 KiB
28Runtime error34ms11784 KiB
29Runtime error26ms11804 KiB
30Wrong answer35ms7320 KiB
31Wrong answer39ms6816 KiB
32Wrong answer43ms6508 KiB
33Wrong answer50ms6496 KiB
34Wrong answer57ms6312 KiB
35Runtime error41ms11120 KiB
36Runtime error48ms10800 KiB
37Runtime error54ms10568 KiB