10282 | 2024-03-29 22:02:18 | 111 | Pletykálkodás | cpp17 | Runtime error 13/100 | 8ms | 5792 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;
if(M!=N-1){
return 1;
}
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);
}
auto dfs1=[&](auto self,int i,int p)->void{
g[i].erase(remove(g[i].begin(),g[i].end(),p),g[i].end());
for(int j:g[i]){
self(self,j,i);
}
};
dfs1(dfs1,1,0);
vector<pair<int,int>>ans;
int l=0;
auto dfs2=[&](auto self,int i)->void{
for(int j:g[i]){
self(self,j);
ans.emplace_back(i,j);
l=j;
}
};
dfs2(dfs2,1);
auto dfs3=[&](auto self,int i)->void{
for(int j:g[i]){
ans.emplace_back(i,j);
if(i==1&&j==l){
ans.pop_back();
}
self(self,j);
}
};
dfs3(dfs3,1);
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 | 1832 KiB | ||||
2 | Runtime error | 3ms | 2024 KiB | ||||
3 | Runtime error | 3ms | 2240 KiB | ||||
subtask2 | 0/9 | ||||||
4 | Runtime error | 3ms | 2472 KiB | ||||
5 | Runtime error | 3ms | 2704 KiB | ||||
6 | Runtime error | 3ms | 2920 KiB | ||||
subtask3 | 13/13 | ||||||
7 | Accepted | 8ms | 4836 KiB | ||||
8 | Accepted | 8ms | 5068 KiB | ||||
9 | Accepted | 8ms | 5404 KiB | ||||
subtask4 | 0/16 | ||||||
10 | Runtime error | 3ms | 3932 KiB | ||||
11 | Runtime error | 3ms | 3968 KiB | ||||
12 | Runtime error | 3ms | 3988 KiB | ||||
subtask5 | 0/25 | ||||||
13 | Runtime error | 3ms | 4080 KiB | ||||
14 | Runtime error | 3ms | 4112 KiB | ||||
15 | Runtime error | 3ms | 4108 KiB | ||||
16 | Runtime error | 3ms | 4204 KiB | ||||
17 | Runtime error | 3ms | 4332 KiB | ||||
18 | Runtime error | 3ms | 4424 KiB | ||||
19 | Runtime error | 3ms | 4656 KiB | ||||
subtask6 | 0/13 | ||||||
20 | Runtime error | 3ms | 4676 KiB | ||||
21 | Runtime error | 3ms | 4956 KiB | ||||
22 | Runtime error | 3ms | 5048 KiB | ||||
23 | Runtime error | 3ms | 5296 KiB | ||||
24 | Runtime error | 3ms | 5272 KiB | ||||
25 | Runtime error | 3ms | 5044 KiB | ||||
26 | Runtime error | 3ms | 5336 KiB | ||||
subtask7 | 0/24 | ||||||
27 | Runtime error | 3ms | 5432 KiB | ||||
28 | Runtime error | 3ms | 5456 KiB | ||||
29 | Runtime error | 3ms | 5476 KiB | ||||
30 | Runtime error | 3ms | 5364 KiB | ||||
31 | Runtime error | 3ms | 5456 KiB | ||||
32 | Runtime error | 3ms | 5468 KiB | ||||
33 | Runtime error | 3ms | 5492 KiB | ||||
34 | Runtime error | 3ms | 5520 KiB | ||||
35 | Runtime error | 3ms | 5468 KiB | ||||
36 | Runtime error | 3ms | 5716 KiB | ||||
37 | Runtime error | 3ms | 5792 KiB |