QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#372142#7936. Eliminate TreeOAleksaWA 62ms15364kbC++141.0kb2024-03-30 23:34:362024-03-30 23:34:36

Judging History

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

  • [2024-03-30 23:34:36]
  • 评测
  • 测评结果:WA
  • 用时:62ms
  • 内存:15364kb
  • [2024-03-30 23:34:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 69;
int n, dp[N][2];
vector<int> g[N];
void dfs(int v, int u)
{
    for (auto it : g[v])
    {
        if (it != u)
            dfs(it, v);
    }
    if (g[v].size() > 1 || v == 1)
    {
        int sum = 0, mn = 1e8, vrtx = 0;
        for (auto it : g[v])
        {
            if (it != u)
            {
                sum += max(dp[1][it], dp[0][it]);
            }
        }
        // 0 je kad ne ucestvuje, 1 kad ucestvuje
        dp[0][v] = sum;
        for (auto it : g[v])
        {
            if (it != u)
            {
                dp[1][v] = max(dp[0][it] + 1 + sum - max(dp[1][it], dp[0][it]), dp[1][v]);
            }
        }
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1;i <= n - 1;i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1, 0);
	int m = max(dp[1][1], dp[1][0]);
	cout << 2 * n - 3 * m << endl;
}

详细

Test #1:

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

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

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

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:

-558753130

result:

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