QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#317740 | #7936. Eliminate Tree | one_god_and_two_dogs# | WA | 1ms | 3488kb | C++17 | 674b | 2024-01-29 16:33:57 | 2024-01-29 16:33:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll=long long ;
int main(){
cin.tie(0)->sync_with_stdio(0);
//freopen("hayasa","r",stdin);
int n;
cin>>n;
vector<vector<int>>G(n);
for(int i=1;i<n;++i){
int a,b;
cin>>a>>b;
--a,--b;
G[a].emplace_back(b);
G[b].emplace_back(a);
}
auto dfs=[&](auto self,int x,int fa)->pair<int,int>{
int s1=INT_MAX,s2=0,c=0;
for(auto y:G[x]){
if(y==fa)continue;
auto [fi,se]=self(self,y,x);
++c;
s2+=se;
s1=min(fi-se,s1);
}
if(c==0)return {0,2};
cout<<x<<" "<<fa<<" "<<s2<<" "<<s2+s1+1<<endl;
return {s2,min(s2+s1+1,s2+2)};
};
auto [r1,r2]=dfs(dfs,1,-1);
cout<<r2<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3488kb
input:
5 1 2 2 3 3 4 3 5
output:
2 1 4 3 1 -1 5 4 4
result:
wrong answer 1st numbers differ - expected: '4', found: '2'