102852024-03-29 23:44:35111Pletykálkodáscpp17Wrong answer 25/1001.6s5508 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<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]){
				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;
			}
		}
		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
2Accepted3ms2020 KiB
3Accepted273ms2760 KiB
subtask20/9
4Accepted3ms2344 KiB
5Accepted2ms2412 KiB
6Wrong answer3ms2540 KiB
subtask30/13
7Time limit exceeded1.6s3704 KiB
8Time limit exceeded1.562s3724 KiB
9Time limit exceeded1.565s3840 KiB
subtask40/16
10Time limit exceeded1.569s3336 KiB
11Time limit exceeded1.541s3524 KiB
12Time limit exceeded1.549s3456 KiB
subtask525/25
13Accepted4ms3608 KiB
14Accepted4ms3656 KiB
15Accepted4ms3680 KiB
16Accepted7ms3620 KiB
17Accepted6ms3624 KiB
18Accepted4ms3676 KiB
19Accepted4ms3676 KiB
subtask60/13
20Accepted393ms4252 KiB
21Wrong answer386ms4368 KiB
22Wrong answer395ms4280 KiB
23Time limit exceeded1.57s3676 KiB
24Accepted1.139s4564 KiB
25Accepted697ms4304 KiB
26Accepted763ms4232 KiB
subtask70/24
27Time limit exceeded1.555s5032 KiB
28Time limit exceeded1.549s4944 KiB
29Time limit exceeded1.554s5176 KiB
30Time limit exceeded1.554s5268 KiB
31Time limit exceeded1.554s5024 KiB
32Time limit exceeded1.582s4784 KiB
33Time limit exceeded1.578s4856 KiB
34Time limit exceeded1.542s4972 KiB
35Time limit exceeded1.559s5508 KiB
36Time limit exceeded1.559s5136 KiB
37Time limit exceeded1.582s5100 KiB