102952024-03-30 10:46:54111Pletykálkodáscpp17Runtime error 0/10059ms8132 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);
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	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,j,k,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 1;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error3ms1832 KiB
2Runtime error3ms2056 KiB
3Wrong answer4ms2704 KiB
subtask20/9
4Runtime error3ms2476 KiB
5Runtime error3ms2696 KiB
6Wrong answer2ms2648 KiB
subtask30/13
7Runtime error14ms3584 KiB
8Runtime error18ms3648 KiB
9Runtime error18ms3616 KiB
subtask40/16
10Runtime error14ms3548 KiB
11Runtime error14ms3552 KiB
12Runtime error14ms3708 KiB
subtask50/25
13Wrong answer3ms3268 KiB
14Wrong answer3ms3448 KiB
15Wrong answer3ms3656 KiB
16Runtime error3ms3732 KiB
17Runtime error3ms3808 KiB
18Runtime error3ms3936 KiB
19Wrong answer3ms4028 KiB
subtask60/13
20Wrong answer4ms4800 KiB
21Wrong answer8ms4756 KiB
22Wrong answer4ms4764 KiB
23Runtime error8ms4844 KiB
24Runtime error4ms4676 KiB
25Runtime error4ms4684 KiB
26Wrong answer7ms5000 KiB
subtask70/24
27Wrong answer27ms7820 KiB
28Wrong answer35ms7888 KiB
29Wrong answer27ms8132 KiB
30Runtime error34ms6176 KiB
31Runtime error37ms6100 KiB
32Runtime error43ms5784 KiB
33Runtime error50ms5792 KiB
34Runtime error59ms5756 KiB
35Wrong answer41ms7264 KiB
36Wrong answer46ms6972 KiB
37Wrong answer54ms6816 KiB