QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372130#7936. Eliminate Treesofija6WA 62ms18616kbC++14692b2024-03-30 23:20:122024-03-30 23:20:13

Judging History

你现在查看的是最新测评结果

  • [2024-03-30 23:20:13]
  • 评测
  • 测评结果:WA
  • 用时:62ms
  • 内存:18616kb
  • [2024-03-30 23:20:12]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define MAXN 200010
using namespace std;
vector<ll> G[MAXN];
ll dp[MAXN][2];
void DFS(ll i,ll p)
{
    for (ll next : G[i])
    {
        if (next!=p)
        {
            DFS(next,i);
            dp[i][1]=max(dp[i][1],dp[i][0]+dp[next][0]+1);
            dp[i][0]+=max(dp[next][0],dp[next][1]);
        }
    }
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,u,v;
    cin >> n;
    for (ll i=1;i<n;i++)
    {
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    DFS(1,0);
    ll m=max(dp[1][0],dp[1][1]);
    cout << 2*n-3*m;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 8396kb

input:

5
1 2
2 3
3 4
3 5

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 3ms
memory: 8256kb

input:

4
1 2
2 3
3 4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 62ms
memory: 18616kb

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:

164966

result:

wrong answer 1st numbers differ - expected: '138182', found: '164966'