#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 1e5 + 7, inf = 1e9;
int n, par[N], head[N], chain[N], pos[N], sz[N], dp[N][2][2], st[N];
vector <int> edge[N];
void dfs(int u, int p){
dp[u][0][0] = dp[u][0][1] = dp[u][1][0] = 0;
if(st[u] == 1){
dp[u][0][1] = inf;
dp[u][0][0] = 1;
}
else if(st[u] == 2){
dp[u][1][0] = inf;
dp[u][0][0] = 1;
}
for(int v : edge[u]){
if(v == p) continue;
par[v] = u;
dfs(v, u);
dp[u][0][0] += min(dp[v][0][0], min(dp[v][1][0], dp[v][0][1]) + 1);
dp[u][1][0] += min(dp[v][1][0], min(dp[v][0][0], dp[v][0][1] + 1));
dp[u][0][1] += min(dp[v][0][1], min(dp[v][0][0], dp[v][1][0] + 1));
}
}
void initialize(int p, vector<int> A, vector<int> B){
n = p;
for(int i = 0; i < n - 1; i++){
edge[A[i]].pb(B[i]);
edge[B[i]].pb(A[i]);
}
dfs(1, 1);
}
int getans(){
return min(dp[1][0][0], min(dp[1][0][1], dp[1][1][0]));
}
int cat(int v) {
st[v] = 1;
dfs(1, 1);
return getans();
}
int dog(int v) {
st[v] = 2;
dfs(1, 1);
return getans();
}
int neighbor(int v) {
st[v] = 0;
dfs(1, 1);
return getans();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2816 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
5 ms |
2688 KB |
Output is correct |
5 |
Correct |
5 ms |
2688 KB |
Output is correct |
6 |
Correct |
4 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
5 ms |
2688 KB |
Output is correct |
9 |
Correct |
5 ms |
2688 KB |
Output is correct |
10 |
Correct |
5 ms |
2688 KB |
Output is correct |
11 |
Correct |
5 ms |
2688 KB |
Output is correct |
12 |
Correct |
5 ms |
2688 KB |
Output is correct |
13 |
Correct |
4 ms |
2660 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
5 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2816 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
5 ms |
2688 KB |
Output is correct |
5 |
Correct |
5 ms |
2688 KB |
Output is correct |
6 |
Correct |
4 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
5 ms |
2688 KB |
Output is correct |
9 |
Correct |
5 ms |
2688 KB |
Output is correct |
10 |
Correct |
5 ms |
2688 KB |
Output is correct |
11 |
Correct |
5 ms |
2688 KB |
Output is correct |
12 |
Correct |
5 ms |
2688 KB |
Output is correct |
13 |
Correct |
4 ms |
2660 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
5 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
18 ms |
2816 KB |
Output is correct |
18 |
Correct |
17 ms |
2688 KB |
Output is correct |
19 |
Correct |
14 ms |
2816 KB |
Output is correct |
20 |
Correct |
5 ms |
2688 KB |
Output is correct |
21 |
Correct |
7 ms |
2688 KB |
Output is correct |
22 |
Correct |
7 ms |
2688 KB |
Output is correct |
23 |
Correct |
20 ms |
2816 KB |
Output is correct |
24 |
Correct |
20 ms |
2688 KB |
Output is correct |
25 |
Correct |
10 ms |
2688 KB |
Output is correct |
26 |
Correct |
7 ms |
2688 KB |
Output is correct |
27 |
Correct |
7 ms |
2688 KB |
Output is correct |
28 |
Correct |
9 ms |
2816 KB |
Output is correct |
29 |
Correct |
21 ms |
2816 KB |
Output is correct |
30 |
Correct |
8 ms |
2688 KB |
Output is correct |
31 |
Correct |
6 ms |
2816 KB |
Output is correct |
32 |
Correct |
10 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2816 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
5 ms |
2688 KB |
Output is correct |
5 |
Correct |
5 ms |
2688 KB |
Output is correct |
6 |
Correct |
4 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
5 ms |
2688 KB |
Output is correct |
9 |
Correct |
5 ms |
2688 KB |
Output is correct |
10 |
Correct |
5 ms |
2688 KB |
Output is correct |
11 |
Correct |
5 ms |
2688 KB |
Output is correct |
12 |
Correct |
5 ms |
2688 KB |
Output is correct |
13 |
Correct |
4 ms |
2660 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
5 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
18 ms |
2816 KB |
Output is correct |
18 |
Correct |
17 ms |
2688 KB |
Output is correct |
19 |
Correct |
14 ms |
2816 KB |
Output is correct |
20 |
Correct |
5 ms |
2688 KB |
Output is correct |
21 |
Correct |
7 ms |
2688 KB |
Output is correct |
22 |
Correct |
7 ms |
2688 KB |
Output is correct |
23 |
Correct |
20 ms |
2816 KB |
Output is correct |
24 |
Correct |
20 ms |
2688 KB |
Output is correct |
25 |
Correct |
10 ms |
2688 KB |
Output is correct |
26 |
Correct |
7 ms |
2688 KB |
Output is correct |
27 |
Correct |
7 ms |
2688 KB |
Output is correct |
28 |
Correct |
9 ms |
2816 KB |
Output is correct |
29 |
Correct |
21 ms |
2816 KB |
Output is correct |
30 |
Correct |
8 ms |
2688 KB |
Output is correct |
31 |
Correct |
6 ms |
2816 KB |
Output is correct |
32 |
Correct |
10 ms |
2688 KB |
Output is correct |
33 |
Execution timed out |
3014 ms |
8060 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |