102902024-03-30 09:54:11111Pletykálkodáscpp17Runtime error 50/1001.549s5696 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;
	if(N>1500)exit(1);
	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<pair<int,int>>ans(N*2);
	for(auto[a,b]:e){
		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;
		int aaa=-1,bbb=-1;
		for(int aa:g[a]){
			for(int bb:g[b]){
				if(aa==b||bb==a){
					continue;
				}
				int ok=0;
				for(int i:g[aa]){
					if(i==bb){
						ok=1;
					}
				}
				if(ok){
					aaa=aa;
					bbb=bb;
				}
			}
		}
		if(aaa!=-1){
			v[aaa]=0;
			v[bbb]=1;
			dfs(dfs,aaa);
			dfs(dfs,bbb);
			if(count(v.begin(),v.end(),-1)>1){
				continue;
			}
			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,aaa);
			s.emplace_back(b,bbb);
			s.emplace_back(a,b);
			s.emplace_back(aaa,bbb);
			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);
			}
			if(s.size()<ans.size()){
				ans=s;
			}
			break;
		}
		fill(v.begin(),v.end(),-1);
		w[0].clear();
		w[1].clear();
		v[a]=0;
		v[b]=1;
		dfs(dfs,a);
		dfs(dfs,b);
		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,b);
		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);
		}
		if(s.size()<ans.size()){
			ans=s;
		}
	}
	cout<<ans.size()<<'\n';
	for(auto[a,b]:ans){
		cout<<a<<' '<<b<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2056 KiB
3Accepted26ms2652 KiB
subtask29/9
4Accepted3ms2244 KiB
5Accepted3ms2456 KiB
6Accepted3ms2668 KiB
subtask30/13
7Runtime error3ms2892 KiB
8Runtime error3ms2980 KiB
9Runtime error2ms2980 KiB
subtask416/16
10Accepted14ms4820 KiB
11Accepted14ms5120 KiB
12Accepted14ms5104 KiB
subtask525/25
13Accepted3ms3412 KiB
14Accepted3ms3672 KiB
15Accepted3ms3884 KiB
16Accepted4ms3844 KiB
17Accepted4ms4092 KiB
18Accepted4ms4052 KiB
19Accepted3ms4192 KiB
subtask60/13
20Accepted32ms4992 KiB
21Accepted81ms4964 KiB
22Accepted101ms5212 KiB
23Time limit exceeded1.549s4788 KiB
24Accepted615ms5696 KiB
25Accepted324ms5500 KiB
26Accepted29ms5420 KiB
subtask70/24
27Runtime error2ms4692 KiB
28Runtime error3ms4816 KiB
29Runtime error2ms4796 KiB
30Runtime error2ms4792 KiB
31Runtime error2ms4792 KiB
32Runtime error2ms4796 KiB
33Runtime error2ms4864 KiB
34Runtime error3ms4768 KiB
35Runtime error3ms4916 KiB
36Runtime error2ms4892 KiB
37Runtime error2ms4852 KiB