QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#372140 | #7936. Eliminate Tree | OAleksa | WA | 50ms | 16220kb | C++14 | 585b | 2024-03-30 23:33:35 | 2024-03-30 23:33:37 |
Judging History
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 p) {
for (auto u : g[v]) {
if (u == p)
continue;
dfs(u, v);
dp[v][0] = max(dp[v][0], max(dp[u][1], dp[u][0]));
dp[v][1] = max(dp[v][1], dp[u][0] + 1);
}
}
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: 8248kb
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: 8308kb
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: 16220kb
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:
390620
result:
wrong answer 1st numbers differ - expected: '138182', found: '390620'