10294 | 2024-03-30 10:46:22 | 111 | Pletykálkodás | cpp17 | Runtime error 0/100 | 59ms | 7428 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,k,j,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 | 1828 KiB | ||||
2 | Runtime error | 3ms | 2020 KiB | ||||
3 | Wrong answer | 4ms | 2836 KiB | ||||
subtask2 | 0/9 | ||||||
4 | Runtime error | 2ms | 2424 KiB | ||||
5 | Runtime error | 2ms | 2568 KiB | ||||
6 | Wrong answer | 3ms | 2596 KiB | ||||
subtask3 | 0/13 | ||||||
7 | Runtime error | 14ms | 3696 KiB | ||||
8 | Runtime error | 18ms | 3784 KiB | ||||
9 | Runtime error | 18ms | 3816 KiB | ||||
subtask4 | 0/16 | ||||||
10 | Runtime error | 14ms | 3732 KiB | ||||
11 | Runtime error | 14ms | 4012 KiB | ||||
12 | Runtime error | 14ms | 3948 KiB | ||||
subtask5 | 0/25 | ||||||
13 | Wrong answer | 3ms | 3044 KiB | ||||
14 | Wrong answer | 3ms | 3120 KiB | ||||
15 | Wrong answer | 3ms | 3240 KiB | ||||
16 | Runtime error | 3ms | 3296 KiB | ||||
17 | Runtime error | 3ms | 3508 KiB | ||||
18 | Runtime error | 3ms | 3428 KiB | ||||
19 | Wrong answer | 3ms | 3504 KiB | ||||
subtask6 | 0/13 | ||||||
20 | Wrong answer | 4ms | 4160 KiB | ||||
21 | Runtime error | 8ms | 3816 KiB | ||||
22 | Wrong answer | 4ms | 4172 KiB | ||||
23 | Runtime error | 7ms | 4096 KiB | ||||
24 | Runtime error | 4ms | 3792 KiB | ||||
25 | Runtime error | 4ms | 3748 KiB | ||||
26 | Wrong answer | 6ms | 4124 KiB | ||||
subtask7 | 0/24 | ||||||
27 | Wrong answer | 27ms | 7048 KiB | ||||
28 | Wrong answer | 35ms | 7428 KiB | ||||
29 | Wrong answer | 27ms | 7336 KiB | ||||
30 | Runtime error | 34ms | 5536 KiB | ||||
31 | Runtime error | 39ms | 5572 KiB | ||||
32 | Runtime error | 43ms | 5284 KiB | ||||
33 | Runtime error | 50ms | 5428 KiB | ||||
34 | Runtime error | 59ms | 5364 KiB | ||||
35 | Wrong answer | 41ms | 6724 KiB | ||||
36 | Wrong answer | 46ms | 6444 KiB | ||||
37 | Wrong answer | 56ms | 6244 KiB |