102922024-03-30 10:39:50111Pletykálkodáscpp17Wrong answer 0/10071ms8264 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);
			}
			cout<<s.size()<<'\n';
			for(auto[a,b]:s){
				cout<<a<<' '<<b<<'\n';
			}
			return 0;
		}
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1828 KiB
2Wrong answer3ms2052 KiB
3Wrong answer4ms2484 KiB
subtask20/9
4Wrong answer3ms2276 KiB
5Wrong answer3ms2444 KiB
6Wrong answer2ms2528 KiB
subtask30/13
7Wrong answer14ms3732 KiB
8Wrong answer20ms3840 KiB
9Wrong answer20ms3956 KiB
subtask40/16
10Wrong answer18ms4792 KiB
11Wrong answer18ms4880 KiB
12Wrong answer17ms4768 KiB
subtask50/25
13Wrong answer3ms3240 KiB
14Wrong answer3ms3452 KiB
15Wrong answer3ms3388 KiB
16Wrong answer3ms3384 KiB
17Wrong answer3ms3376 KiB
18Wrong answer3ms3584 KiB
19Wrong answer3ms3604 KiB
subtask60/13
20Wrong answer4ms4144 KiB
21Wrong answer8ms4092 KiB
22Wrong answer4ms4252 KiB
23Wrong answer8ms4372 KiB
24Wrong answer6ms4224 KiB
25Wrong answer6ms4280 KiB
26Wrong answer7ms4688 KiB
subtask70/24
27Wrong answer26ms8252 KiB
28Wrong answer35ms8244 KiB
29Wrong answer26ms8264 KiB
30Wrong answer37ms6372 KiB
31Wrong answer43ms5784 KiB
32Wrong answer50ms5392 KiB
33Wrong answer59ms5348 KiB
34Wrong answer71ms5204 KiB
35Wrong answer46ms7036 KiB
36Wrong answer52ms6620 KiB
37Wrong answer61ms6708 KiB