#include <bits/stdc++.h>
#include "catdog.h"
#define INF 0x3f3f3f3f
using namespace std;
const int kN = 1e5;
vector<int> g[1 + kN];
short col[1 + kN];
int dp[1 + kN][2];
void minSelf(int &x, int y) {
if (y < x) {
x = y;
}
}
void dfs(int u, int par) {
dp[u][0] = dp[u][1] = 0;
for (int v : g[u]) {
if (v != par) {
dfs(v, u);
for (int i = 0; i < 2; ++i) {
dp[u][i] += min(dp[v][i], dp[v][i ^ 1] + 1);
}
}
}
if (col[u] < 2) {
dp[u][col[u]] = INF;
}
}
void initialize(int N, vector<int> A, vector<int> B) {
for (int i = 0; i < N - 1; ++i) {
g[A[i]].emplace_back(B[i]);
g[B[i]].emplace_back(A[i]);
}
for (int v = 1; v <= N; ++v) {
col[v] = 2;
}
}
int cat(int v) {
col[v] = 0;
dfs(1, 0);
return min(dp[1][0], dp[1][1]);
}
int dog(int v) {
col[v] = 1;
dfs(1, 0);
return min(dp[1][0], dp[1][1]);
}
int neighbor(int v) {
col[v] = 2;
dfs(1, 0);
return min(dp[1][0], dp[1][1]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2648 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2656 KB |
Output is correct |
12 |
Correct |
2 ms |
2592 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2648 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2656 KB |
Output is correct |
12 |
Correct |
2 ms |
2592 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
13 ms |
2636 KB |
Output is correct |
18 |
Correct |
13 ms |
2720 KB |
Output is correct |
19 |
Correct |
8 ms |
2704 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
4 ms |
2636 KB |
Output is correct |
22 |
Correct |
4 ms |
2628 KB |
Output is correct |
23 |
Correct |
14 ms |
2656 KB |
Output is correct |
24 |
Correct |
11 ms |
2712 KB |
Output is correct |
25 |
Correct |
5 ms |
2636 KB |
Output is correct |
26 |
Correct |
3 ms |
2636 KB |
Output is correct |
27 |
Correct |
3 ms |
2636 KB |
Output is correct |
28 |
Correct |
4 ms |
2636 KB |
Output is correct |
29 |
Correct |
14 ms |
2768 KB |
Output is correct |
30 |
Correct |
3 ms |
2636 KB |
Output is correct |
31 |
Correct |
3 ms |
2636 KB |
Output is correct |
32 |
Correct |
4 ms |
2656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2648 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2656 KB |
Output is correct |
12 |
Correct |
2 ms |
2592 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
13 ms |
2636 KB |
Output is correct |
18 |
Correct |
13 ms |
2720 KB |
Output is correct |
19 |
Correct |
8 ms |
2704 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
4 ms |
2636 KB |
Output is correct |
22 |
Correct |
4 ms |
2628 KB |
Output is correct |
23 |
Correct |
14 ms |
2656 KB |
Output is correct |
24 |
Correct |
11 ms |
2712 KB |
Output is correct |
25 |
Correct |
5 ms |
2636 KB |
Output is correct |
26 |
Correct |
3 ms |
2636 KB |
Output is correct |
27 |
Correct |
3 ms |
2636 KB |
Output is correct |
28 |
Correct |
4 ms |
2636 KB |
Output is correct |
29 |
Correct |
14 ms |
2768 KB |
Output is correct |
30 |
Correct |
3 ms |
2636 KB |
Output is correct |
31 |
Correct |
3 ms |
2636 KB |
Output is correct |
32 |
Correct |
4 ms |
2656 KB |
Output is correct |
33 |
Execution timed out |
3015 ms |
7068 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |