102942024-03-30 10:46:22111Pletykálkodáscpp17Runtime error 0/10059ms7428 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,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 1;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error3ms1828 KiB
2Runtime error3ms2020 KiB
3Wrong answer4ms2836 KiB
subtask20/9
4Runtime error2ms2424 KiB
5Runtime error2ms2568 KiB
6Wrong answer3ms2596 KiB
subtask30/13
7Runtime error14ms3696 KiB
8Runtime error18ms3784 KiB
9Runtime error18ms3816 KiB
subtask40/16
10Runtime error14ms3732 KiB
11Runtime error14ms4012 KiB
12Runtime error14ms3948 KiB
subtask50/25
13Wrong answer3ms3044 KiB
14Wrong answer3ms3120 KiB
15Wrong answer3ms3240 KiB
16Runtime error3ms3296 KiB
17Runtime error3ms3508 KiB
18Runtime error3ms3428 KiB
19Wrong answer3ms3504 KiB
subtask60/13
20Wrong answer4ms4160 KiB
21Runtime error8ms3816 KiB
22Wrong answer4ms4172 KiB
23Runtime error7ms4096 KiB
24Runtime error4ms3792 KiB
25Runtime error4ms3748 KiB
26Wrong answer6ms4124 KiB
subtask70/24
27Wrong answer27ms7048 KiB
28Wrong answer35ms7428 KiB
29Wrong answer27ms7336 KiB
30Runtime error34ms5536 KiB
31Runtime error39ms5572 KiB
32Runtime error43ms5284 KiB
33Runtime error50ms5428 KiB
34Runtime error59ms5364 KiB
35Wrong answer41ms6724 KiB
36Wrong answer46ms6444 KiB
37Wrong answer56ms6244 KiB