QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#386938 | #7936. Eliminate Tree | carbon111# | WA | 89ms | 31636kb | C++14 | 750b | 2024-04-11 21:46:30 | 2024-04-11 21:46:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin>>n;
vector<map<int,int>>g(n+1);
vector<int>d(n+1);
for(int i = 0;i<n-1;i++){
int a,b;cin>>a>>b;
g[a][b]++;
g[b][a]++;
d[a]++,d[b]++;
}
int cnt = 0;
function<bool(int,int)> dfs = [&](int u,int fa)->bool{
bool ok = true;
for(auto x:g[u]){
int v = x.first;
if(v==fa)continue;
ok &= dfs(v,u);
}
if(ok==false){
return true;
}
if(d[fa]==1||d[fa]==2){
cnt++;
d[u]--;
return false;
}
d[fa]--;
//cout<<fa<<" "<<"\n";
cnt+=2;
d[u]--;
return true;
};
dfs(1,0);
cout<<cnt<<"\n";
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int t = 1;
while(t--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3856kb
input:
5 1 2 2 3 3 4 3 5
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
4 1 2 2 3 3 4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 89ms
memory: 31636kb
input:
196666 32025 108673 181779 17115 162570 134230 93003 39673 89144 1269 185919 154408 34896 65369 35860 44720 55698 1390 45520 189805 147867 124511 135459 132555 87303 18031 176314 59695 33352 130640 87272 39716 35749 108807 143493 94486 126512 116598 40212 70895 132216 80855 22241 188737 150354 17346...
output:
191618
result:
wrong answer 1st numbers differ - expected: '138182', found: '191618'