10284 | 2024-03-29 23:44:03 | 111 | Pletykálkodás | cpp17 | Wrong answer 0/100 | 1.6s | 5460 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;
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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2056 KiB | ||||
3 | Wrong answer | 282ms | 2744 KiB | ||||
subtask2 | 0/9 | ||||||
4 | Accepted | 3ms | 2332 KiB | ||||
5 | Wrong answer | 2ms | 2420 KiB | ||||
6 | Wrong answer | 3ms | 2564 KiB | ||||
subtask3 | 0/13 | ||||||
7 | Time limit exceeded | 1.6s | 3552 KiB | ||||
8 | Time limit exceeded | 1.577s | 3604 KiB | ||||
9 | Time limit exceeded | 1.552s | 3928 KiB | ||||
subtask4 | 0/16 | ||||||
10 | Time limit exceeded | 1.56s | 3076 KiB | ||||
11 | Time limit exceeded | 1.552s | 3268 KiB | ||||
12 | Time limit exceeded | 1.557s | 3468 KiB | ||||
subtask5 | 0/25 | ||||||
13 | Wrong answer | 4ms | 3544 KiB | ||||
14 | Wrong answer | 4ms | 3424 KiB | ||||
15 | Wrong answer | 4ms | 3592 KiB | ||||
16 | Wrong answer | 7ms | 3660 KiB | ||||
17 | Wrong answer | 6ms | 3516 KiB | ||||
18 | Wrong answer | 4ms | 3576 KiB | ||||
19 | Wrong answer | 4ms | 3576 KiB | ||||
subtask6 | 0/13 | ||||||
20 | Wrong answer | 377ms | 4316 KiB | ||||
21 | Wrong answer | 370ms | 4296 KiB | ||||
22 | Wrong answer | 384ms | 4344 KiB | ||||
23 | Time limit exceeded | 1.572s | 3612 KiB | ||||
24 | Wrong answer | 1.133s | 4740 KiB | ||||
25 | Wrong answer | 717ms | 4516 KiB | ||||
26 | Wrong answer | 842ms | 4456 KiB | ||||
subtask7 | 0/24 | ||||||
27 | Time limit exceeded | 1.555s | 5204 KiB | ||||
28 | Time limit exceeded | 1.56s | 5444 KiB | ||||
29 | Time limit exceeded | 1.574s | 5408 KiB | ||||
30 | Time limit exceeded | 1.549s | 5292 KiB | ||||
31 | Time limit exceeded | 1.539s | 5320 KiB | ||||
32 | Time limit exceeded | 1.542s | 5020 KiB | ||||
33 | Time limit exceeded | 1.569s | 5088 KiB | ||||
34 | Time limit exceeded | 1.575s | 5384 KiB | ||||
35 | Time limit exceeded | 1.562s | 5460 KiB | ||||
36 | Time limit exceeded | 1.549s | 5192 KiB | ||||
37 | Time limit exceeded | 1.57s | 5036 KiB |