10295 | 2024-03-30 10:46:54 | 111 | Pletykálkodás | cpp17 | Runtime error 0/100 | 59ms | 8132 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);
for(int i=0;i<M;i++){
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
vector<tuple<int,int,int,int>>c;
for(int i=1;i<=N;i++){
vector<int>v(N+1);
v[i]=-1;
for(int j:g[i]){
v[j]=-1;
}
for(int j:g[i]){
for(int k:g[j]){
if(v[k]<0){
continue;
}
if(v[k]>0){
c.emplace_back(i,j,k,v[k]);
continue;
}
v[k]=j;
}
}
}
for(auto[a,b,aa,bb]:c){
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;
v[aa]=0;
v[bb]=1;
dfs(dfs,aa);
dfs(dfs,bb);
if(count(v.begin(),v.end(),-1)==1){
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,aa);
s.emplace_back(b,bb);
s.emplace_back(a,b);
s.emplace_back(aa,bb);
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);
}
cout<<s.size()<<'\n';
for(auto[a,b]:s){
cout<<a<<' '<<b<<'\n';
}
return 0;
}
}
return 1;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Runtime error | 3ms | 1832 KiB | ||||
2 | Runtime error | 3ms | 2056 KiB | ||||
3 | Wrong answer | 4ms | 2704 KiB | ||||
subtask2 | 0/9 | ||||||
4 | Runtime error | 3ms | 2476 KiB | ||||
5 | Runtime error | 3ms | 2696 KiB | ||||
6 | Wrong answer | 2ms | 2648 KiB | ||||
subtask3 | 0/13 | ||||||
7 | Runtime error | 14ms | 3584 KiB | ||||
8 | Runtime error | 18ms | 3648 KiB | ||||
9 | Runtime error | 18ms | 3616 KiB | ||||
subtask4 | 0/16 | ||||||
10 | Runtime error | 14ms | 3548 KiB | ||||
11 | Runtime error | 14ms | 3552 KiB | ||||
12 | Runtime error | 14ms | 3708 KiB | ||||
subtask5 | 0/25 | ||||||
13 | Wrong answer | 3ms | 3268 KiB | ||||
14 | Wrong answer | 3ms | 3448 KiB | ||||
15 | Wrong answer | 3ms | 3656 KiB | ||||
16 | Runtime error | 3ms | 3732 KiB | ||||
17 | Runtime error | 3ms | 3808 KiB | ||||
18 | Runtime error | 3ms | 3936 KiB | ||||
19 | Wrong answer | 3ms | 4028 KiB | ||||
subtask6 | 0/13 | ||||||
20 | Wrong answer | 4ms | 4800 KiB | ||||
21 | Wrong answer | 8ms | 4756 KiB | ||||
22 | Wrong answer | 4ms | 4764 KiB | ||||
23 | Runtime error | 8ms | 4844 KiB | ||||
24 | Runtime error | 4ms | 4676 KiB | ||||
25 | Runtime error | 4ms | 4684 KiB | ||||
26 | Wrong answer | 7ms | 5000 KiB | ||||
subtask7 | 0/24 | ||||||
27 | Wrong answer | 27ms | 7820 KiB | ||||
28 | Wrong answer | 35ms | 7888 KiB | ||||
29 | Wrong answer | 27ms | 8132 KiB | ||||
30 | Runtime error | 34ms | 6176 KiB | ||||
31 | Runtime error | 37ms | 6100 KiB | ||||
32 | Runtime error | 43ms | 5784 KiB | ||||
33 | Runtime error | 50ms | 5792 KiB | ||||
34 | Runtime error | 59ms | 5756 KiB | ||||
35 | Wrong answer | 41ms | 7264 KiB | ||||
36 | Wrong answer | 46ms | 6972 KiB | ||||
37 | Wrong answer | 54ms | 6816 KiB |