QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#497410#7936. Eliminate TreedeepthoughtWA 58ms18676kbC++231.1kb2024-07-29 04:30:362024-07-29 04:30:37

Judging History

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

  • [2024-07-29 04:30:37]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:18676kb
  • [2024-07-29 04:30:36]
  • 提交

answer

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

const int MAXX = 2e5 + 5;

#define int long long

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 = - 1e15;
    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] = 1e15;
    }

    dfs(1, - 1);

    cout << dpmit[1] << endl;


}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 6760kb

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: 6672kb

input:

4
1 2
2 3
3 4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 58ms
memory: 18676kb

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'