QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#39762 | #989. Into Cactus | Froggygua | WA | 4ms | 8344kb | C++17 | 758b | 2022-07-13 14:15:08 | 2022-07-13 14:15:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define N 200020
typedef long long ll;
int n;
vector<pair<int,int> > ans;
vector<int> G[N];
int dfs(int u,int fa){
vector<int> A;
int t=0;
for(auto v:G[u]){
if(v==fa)continue;
int z=dfs(v,u);
if(z==-1){
A.push_back(v);
}
else{
t=z;
}
}
if(t)ans.emplace_back(t,u);
for(int i=0;i<(int)A.size()-1;i+=2){
ans.emplace_back(A[i],A[i+1]);
}
if(A.size()&1){
return A.back();
}
return -1;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<n;++i){
int u,v;
cin>>u>>v;
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1,0);
cout<<ans.size()<<'\n';
for(auto [x,y]:ans){
cout<<x<<' '<<y<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8280kb
input:
6 6 4 3 1 3 6 4 5 2 3
output:
2 5 6 6 2
result:
ok OK!
Test #2:
score: 0
Accepted
time: 4ms
memory: 8156kb
input:
1
output:
0
result:
ok OK!
Test #3:
score: 0
Accepted
time: 2ms
memory: 8276kb
input:
2 1 2
output:
0
result:
ok OK!
Test #4:
score: 0
Accepted
time: 2ms
memory: 8276kb
input:
3 3 1 1 2
output:
1 3 2
result:
ok OK!
Test #5:
score: 0
Accepted
time: 4ms
memory: 8208kb
input:
4 1 3 1 4 2 1
output:
1 3 4
result:
ok OK!
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 8344kb
input:
5 5 4 2 3 1 2 1 4
output:
1 5 1
result:
wrong answer Integer 1 violates the range [2, 2]