QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#309931 | #7936. Eliminate Tree | ucup-team139# | WA | 52ms | 14724kb | C++17 | 649b | 2024-01-20 22:47:20 | 2024-01-20 22:47:21 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
constexpr int MAXN = 200'005;
vector<int> g[MAXN];
pair<int, bool> dfs(int n, int p)
{
int ans = 0;
int cl = 0;
for (int a : g[n])
if (a != p)
{
auto d = dfs(a, n);
ans += d.first;
cl += d.second;
}
if (cl == 0)
return {ans, 1};
return {ans + 2 * (cl - 1) + 1, 0};
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 0, u, v; i < n - 1; i++)
{
scanf("%d %d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
auto p = dfs(1, 1);
printf("%d\n", p.first + p.second);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8580kb
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: 8600kb
input:
4 1 2 2 3 3 4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 52ms
memory: 14724kb
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:
138181
result:
wrong answer 1st numbers differ - expected: '138182', found: '138181'