#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] ^ 1] = 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]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 KB |
Output is correct |
8 |
Correct |
3 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 |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
1 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 KB |
Output is correct |
8 |
Correct |
3 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 |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
1 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
12 ms |
2636 KB |
Output is correct |
18 |
Correct |
14 ms |
2636 KB |
Output is correct |
19 |
Correct |
7 ms |
2696 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
3 ms |
2636 KB |
Output is correct |
22 |
Correct |
3 ms |
2636 KB |
Output is correct |
23 |
Correct |
14 ms |
2708 KB |
Output is correct |
24 |
Correct |
12 ms |
2636 KB |
Output is correct |
25 |
Correct |
6 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 |
15 ms |
2756 KB |
Output is correct |
30 |
Correct |
3 ms |
2636 KB |
Output is correct |
31 |
Correct |
3 ms |
2636 KB |
Output is correct |
32 |
Correct |
5 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 KB |
Output is correct |
8 |
Correct |
3 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 |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
1 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
12 ms |
2636 KB |
Output is correct |
18 |
Correct |
14 ms |
2636 KB |
Output is correct |
19 |
Correct |
7 ms |
2696 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
3 ms |
2636 KB |
Output is correct |
22 |
Correct |
3 ms |
2636 KB |
Output is correct |
23 |
Correct |
14 ms |
2708 KB |
Output is correct |
24 |
Correct |
12 ms |
2636 KB |
Output is correct |
25 |
Correct |
6 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 |
15 ms |
2756 KB |
Output is correct |
30 |
Correct |
3 ms |
2636 KB |
Output is correct |
31 |
Correct |
3 ms |
2636 KB |
Output is correct |
32 |
Correct |
5 ms |
2636 KB |
Output is correct |
33 |
Execution timed out |
3066 ms |
5980 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |