102832024-03-29 22:46:13111Pletykálkodáscpp17Wrong answer 0/1001.582s8192 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];
				w[v[i]].emplace_back(i,j);
				self(self,j);
			}
		};
		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
1Wrong answer3ms1824 KiB
2Accepted3ms2020 KiB
3Wrong answer116ms2756 KiB
subtask20/9
4Accepted3ms2352 KiB
5Wrong answer2ms2420 KiB
6Wrong answer3ms2656 KiB
subtask30/13
7Time limit exceeded1.575s3452 KiB
8Time limit exceeded1.562s3608 KiB
9Time limit exceeded1.562s3840 KiB
subtask40/16
10Time limit exceeded1.562s3532 KiB
11Time limit exceeded1.577s3840 KiB
12Time limit exceeded1.582s4252 KiB
subtask50/25
13Wrong answer4ms4196 KiB
14Wrong answer4ms4524 KiB
15Wrong answer4ms4732 KiB
16Wrong answer4ms4880 KiB
17Wrong answer4ms4708 KiB
18Wrong answer4ms4712 KiB
19Wrong answer3ms4712 KiB
subtask60/13
20Wrong answer230ms5720 KiB
21Wrong answer218ms5628 KiB
22Wrong answer228ms5696 KiB
23Time limit exceeded1.552s5268 KiB
24Wrong answer578ms6520 KiB
25Wrong answer303ms6284 KiB
26Wrong answer218ms6204 KiB
subtask70/24
27Time limit exceeded1.542s7096 KiB
28Time limit exceeded1.57s7376 KiB
29Time limit exceeded1.562s7536 KiB
30Time limit exceeded1.569s7556 KiB
31Time limit exceeded1.57s7520 KiB
32Time limit exceeded1.557s7452 KiB
33Time limit exceeded1.56s7416 KiB
34Time limit exceeded1.58s7468 KiB
35Time limit exceeded1.57s7908 KiB
36Time limit exceeded1.582s7940 KiB
37Time limit exceeded1.575s8192 KiB