QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#497409#7936. Eliminate TreedeepthoughtWA 50ms16172kbC++231.1kb2024-07-29 04:29:352024-07-29 04:29:35

Judging History

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

  • [2024-07-29 04:29:35]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:16172kb
  • [2024-07-29 04:29:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int MAXX = 2e5 + 5;

vector <int> g[MAXX];
int n;
int dpmit[MAXX];
int dpohne[MAXX];
void dfs(int x, int par) {
    if(x != 1 && g[x].size() == 1) {
        dpmit[x] = 2;
        dpohne[x] = 0;
        return;
    }
    int chs = - 1e9;
    int idx = - 1;
    int sum = 0;
    for(auto y: g[x]) {
        if(y == par) continue;
        dfs(y, x);
        sum += dpmit[y];
        if(chs < dpohne[y] - dpmit[y]) {
            chs = dpohne[y] - dpmit[y];
            idx = y;
        }
    }
    dpohne[x] = sum;
    dpmit[x] = min(sum + 2, sum - dpmit[idx] + dpohne[idx] + 1);
    // cout << x << " " << dpmit[x] << " " << dpohne[x] << endl;
    return;
}
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    
    for(int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 0; i < MAXX; i++) {
        dpmit[i] = dpohne[i] = 1e9;
    }

    dfs(1, - 1);

    cout << dpmit[1] << endl;


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5116kb

input:

5
1 2
2 3
3 4
3 5

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 2ms
memory: 5184kb

input:

4
1 2
2 3
3 4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 50ms
memory: 16172kb

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:

191621

result:

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