QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#746588 | #7936. Eliminate Tree | Mine_King | WA | 33ms | 9516kb | C++14 | 1.2kb | 2024-11-14 15:03:26 | 2024-11-14 15:03:28 |
Judging History
answer
// 長い夜の終わりを信じながら
// Think twice, code once.
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define eputchar(c) putc(c, stderr)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define eputs(str) fputs(str, stderr), putc('\n', stderr)
using namespace std;
int n, dp[200005][2];
struct graph {
int tot, hd[200005];
int nxt[400005], to[400005];
void add(int u, int v) {
nxt[++tot] = hd[u];
hd[u] = tot;
to[tot] = v;
return;
}
} g;
void dfs(int now, int fa) {
for (int i = g.hd[now]; i; i = g.nxt[i])
if (g.to[i] != fa) {
dfs(g.to[i], now);
dp[now][1] += min(dp[g.to[i]][0], dp[g.to[i]][1] + 2);
}
dp[now][0] = 0x3f3f3f3f;
for (int i = g.hd[now]; i; i = g.nxt[i])
if (g.to[i] != fa) {
if (dp[g.to[i]][0] < dp[g.to[i]][1] + 1)
dp[now][0] = min(dp[now][0], dp[now][1] - dp[g.to[i]][0] + dp[g.to[i]][1] + 1);
else dp[now][0] = min(dp[now][0], dp[now][1] - 1);
}
return;
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int u, v;
scanf("%d%d", &u, &v);
g.add(u, v), g.add(v, u);
}
dfs(1, 0);
printf("%d\n", min(dp[1][0], dp[1][1] + 1));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7880kb
input:
5 1 2 2 3 3 4 3 5
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5832kb
input:
4 1 2 2 3 3 4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 33ms
memory: 9516kb
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'