QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#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;
}
详细
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'