10296 | 2024-03-30 10:48:41 | 111 | Pletykálkodás | cpp17 | Runtime error 0/100 | 59ms | 8120 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,v[k],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 | 2016 KiB | ||||
3 | Accepted | 4ms | 2668 KiB | ||||
subtask2 | 0/9 | ||||||
4 | Runtime error | 3ms | 2444 KiB | ||||
5 | Runtime error | 3ms | 2532 KiB | ||||
6 | Accepted | 3ms | 2528 KiB | ||||
subtask3 | 0/13 | ||||||
7 | Runtime error | 16ms | 3508 KiB | ||||
8 | Runtime error | 20ms | 3704 KiB | ||||
9 | Runtime error | 19ms | 3776 KiB | ||||
subtask4 | 0/16 | ||||||
10 | Runtime error | 14ms | 3696 KiB | ||||
11 | Runtime error | 14ms | 3952 KiB | ||||
12 | Runtime error | 14ms | 4272 KiB | ||||
subtask5 | 0/25 | ||||||
13 | Accepted | 3ms | 3580 KiB | ||||
14 | Accepted | 3ms | 3708 KiB | ||||
15 | Accepted | 3ms | 3836 KiB | ||||
16 | Runtime error | 3ms | 3780 KiB | ||||
17 | Runtime error | 3ms | 3872 KiB | ||||
18 | Runtime error | 3ms | 3780 KiB | ||||
19 | Accepted | 3ms | 3876 KiB | ||||
subtask6 | 0/13 | ||||||
20 | Accepted | 4ms | 4556 KiB | ||||
21 | Accepted | 8ms | 4600 KiB | ||||
22 | Accepted | 4ms | 4824 KiB | ||||
23 | Runtime error | 8ms | 4844 KiB | ||||
24 | Runtime error | 6ms | 4720 KiB | ||||
25 | Runtime error | 4ms | 4760 KiB | ||||
26 | Accepted | 6ms | 5084 KiB | ||||
subtask7 | 0/24 | ||||||
27 | Accepted | 27ms | 7776 KiB | ||||
28 | Accepted | 35ms | 8120 KiB | ||||
29 | Accepted | 27ms | 8032 KiB | ||||
30 | Runtime error | 35ms | 6308 KiB | ||||
31 | Runtime error | 39ms | 6124 KiB | ||||
32 | Runtime error | 43ms | 5944 KiB | ||||
33 | Runtime error | 52ms | 5892 KiB | ||||
34 | Runtime error | 59ms | 5844 KiB | ||||
35 | Accepted | 41ms | 7204 KiB | ||||
36 | Accepted | 46ms | 6884 KiB | ||||
37 | Accepted | 54ms | 6812 KiB |