10285 | 2024-03-29 23:44:35 | 111 | Pletykálkodás | cpp17 | Wrong answer 25/100 | 1.6s | 5508 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2020 KiB | ||||
3 | Accepted | 273ms | 2760 KiB | ||||
subtask2 | 0/9 | ||||||
4 | Accepted | 3ms | 2344 KiB | ||||
5 | Accepted | 2ms | 2412 KiB | ||||
6 | Wrong answer | 3ms | 2540 KiB | ||||
subtask3 | 0/13 | ||||||
7 | Time limit exceeded | 1.6s | 3704 KiB | ||||
8 | Time limit exceeded | 1.562s | 3724 KiB | ||||
9 | Time limit exceeded | 1.565s | 3840 KiB | ||||
subtask4 | 0/16 | ||||||
10 | Time limit exceeded | 1.569s | 3336 KiB | ||||
11 | Time limit exceeded | 1.541s | 3524 KiB | ||||
12 | Time limit exceeded | 1.549s | 3456 KiB | ||||
subtask5 | 25/25 | ||||||
13 | Accepted | 4ms | 3608 KiB | ||||
14 | Accepted | 4ms | 3656 KiB | ||||
15 | Accepted | 4ms | 3680 KiB | ||||
16 | Accepted | 7ms | 3620 KiB | ||||
17 | Accepted | 6ms | 3624 KiB | ||||
18 | Accepted | 4ms | 3676 KiB | ||||
19 | Accepted | 4ms | 3676 KiB | ||||
subtask6 | 0/13 | ||||||
20 | Accepted | 393ms | 4252 KiB | ||||
21 | Wrong answer | 386ms | 4368 KiB | ||||
22 | Wrong answer | 395ms | 4280 KiB | ||||
23 | Time limit exceeded | 1.57s | 3676 KiB | ||||
24 | Accepted | 1.139s | 4564 KiB | ||||
25 | Accepted | 697ms | 4304 KiB | ||||
26 | Accepted | 763ms | 4232 KiB | ||||
subtask7 | 0/24 | ||||||
27 | Time limit exceeded | 1.555s | 5032 KiB | ||||
28 | Time limit exceeded | 1.549s | 4944 KiB | ||||
29 | Time limit exceeded | 1.554s | 5176 KiB | ||||
30 | Time limit exceeded | 1.554s | 5268 KiB | ||||
31 | Time limit exceeded | 1.554s | 5024 KiB | ||||
32 | Time limit exceeded | 1.582s | 4784 KiB | ||||
33 | Time limit exceeded | 1.578s | 4856 KiB | ||||
34 | Time limit exceeded | 1.542s | 4972 KiB | ||||
35 | Time limit exceeded | 1.559s | 5508 KiB | ||||
36 | Time limit exceeded | 1.559s | 5136 KiB | ||||
37 | Time limit exceeded | 1.582s | 5100 KiB |