#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1 << 20)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 100111
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
int n;
vector<int> adj[maxn];
int col[maxn], dp[maxn][3];
void DFS(int x, int p){
dp[x][1] = dp[x][2] = 0;
if(col[x] != 0)
dp[x][3 - col[x]] = INF;
for(int v : adj[x]){
if(v == p)
continue;
DFS(v, x);
dp[x][1] += min(dp[v][1], 1 + dp[v][2]);
dp[x][2] += min(1 + dp[v][1], dp[v][2]);
}
}
int solve(){
DFS(1, -1);
return min(dp[1][1], dp[1][2]);
}
void initialize(int N, vector<int> A, vector<int> B){
n = N;
for(int i = 0; i < n - 1; i++){
adj[A[i]].pb(B[i]);
adj[B[i]].pb(A[i]);
}
}
int cat(int v){
col[v] = 1;
return solve();
}
int dog(int v){
col[v] = 2;
return solve();
}
int neighbor(int v){
col[v] = 0;
return solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2792 KB |
Output is correct |
3 |
Correct |
7 ms |
2900 KB |
Output is correct |
4 |
Correct |
5 ms |
2900 KB |
Output is correct |
5 |
Correct |
6 ms |
2900 KB |
Output is correct |
6 |
Correct |
4 ms |
2944 KB |
Output is correct |
7 |
Correct |
6 ms |
2944 KB |
Output is correct |
8 |
Correct |
4 ms |
2944 KB |
Output is correct |
9 |
Correct |
6 ms |
2944 KB |
Output is correct |
10 |
Correct |
5 ms |
2996 KB |
Output is correct |
11 |
Correct |
5 ms |
3076 KB |
Output is correct |
12 |
Correct |
5 ms |
3076 KB |
Output is correct |
13 |
Correct |
6 ms |
3076 KB |
Output is correct |
14 |
Correct |
5 ms |
3076 KB |
Output is correct |
15 |
Correct |
5 ms |
3076 KB |
Output is correct |
16 |
Correct |
4 ms |
3076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2792 KB |
Output is correct |
3 |
Correct |
7 ms |
2900 KB |
Output is correct |
4 |
Correct |
5 ms |
2900 KB |
Output is correct |
5 |
Correct |
6 ms |
2900 KB |
Output is correct |
6 |
Correct |
4 ms |
2944 KB |
Output is correct |
7 |
Correct |
6 ms |
2944 KB |
Output is correct |
8 |
Correct |
4 ms |
2944 KB |
Output is correct |
9 |
Correct |
6 ms |
2944 KB |
Output is correct |
10 |
Correct |
5 ms |
2996 KB |
Output is correct |
11 |
Correct |
5 ms |
3076 KB |
Output is correct |
12 |
Correct |
5 ms |
3076 KB |
Output is correct |
13 |
Correct |
6 ms |
3076 KB |
Output is correct |
14 |
Correct |
5 ms |
3076 KB |
Output is correct |
15 |
Correct |
5 ms |
3076 KB |
Output is correct |
16 |
Correct |
4 ms |
3076 KB |
Output is correct |
17 |
Correct |
14 ms |
3168 KB |
Output is correct |
18 |
Correct |
17 ms |
3220 KB |
Output is correct |
19 |
Correct |
11 ms |
3248 KB |
Output is correct |
20 |
Correct |
6 ms |
3248 KB |
Output is correct |
21 |
Correct |
6 ms |
3280 KB |
Output is correct |
22 |
Correct |
7 ms |
3280 KB |
Output is correct |
23 |
Correct |
17 ms |
3348 KB |
Output is correct |
24 |
Correct |
16 ms |
3452 KB |
Output is correct |
25 |
Correct |
10 ms |
3452 KB |
Output is correct |
26 |
Correct |
7 ms |
3452 KB |
Output is correct |
27 |
Correct |
7 ms |
3452 KB |
Output is correct |
28 |
Correct |
7 ms |
3452 KB |
Output is correct |
29 |
Correct |
20 ms |
3524 KB |
Output is correct |
30 |
Correct |
6 ms |
3524 KB |
Output is correct |
31 |
Correct |
5 ms |
3524 KB |
Output is correct |
32 |
Correct |
8 ms |
3524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2792 KB |
Output is correct |
3 |
Correct |
7 ms |
2900 KB |
Output is correct |
4 |
Correct |
5 ms |
2900 KB |
Output is correct |
5 |
Correct |
6 ms |
2900 KB |
Output is correct |
6 |
Correct |
4 ms |
2944 KB |
Output is correct |
7 |
Correct |
6 ms |
2944 KB |
Output is correct |
8 |
Correct |
4 ms |
2944 KB |
Output is correct |
9 |
Correct |
6 ms |
2944 KB |
Output is correct |
10 |
Correct |
5 ms |
2996 KB |
Output is correct |
11 |
Correct |
5 ms |
3076 KB |
Output is correct |
12 |
Correct |
5 ms |
3076 KB |
Output is correct |
13 |
Correct |
6 ms |
3076 KB |
Output is correct |
14 |
Correct |
5 ms |
3076 KB |
Output is correct |
15 |
Correct |
5 ms |
3076 KB |
Output is correct |
16 |
Correct |
4 ms |
3076 KB |
Output is correct |
17 |
Correct |
14 ms |
3168 KB |
Output is correct |
18 |
Correct |
17 ms |
3220 KB |
Output is correct |
19 |
Correct |
11 ms |
3248 KB |
Output is correct |
20 |
Correct |
6 ms |
3248 KB |
Output is correct |
21 |
Correct |
6 ms |
3280 KB |
Output is correct |
22 |
Correct |
7 ms |
3280 KB |
Output is correct |
23 |
Correct |
17 ms |
3348 KB |
Output is correct |
24 |
Correct |
16 ms |
3452 KB |
Output is correct |
25 |
Correct |
10 ms |
3452 KB |
Output is correct |
26 |
Correct |
7 ms |
3452 KB |
Output is correct |
27 |
Correct |
7 ms |
3452 KB |
Output is correct |
28 |
Correct |
7 ms |
3452 KB |
Output is correct |
29 |
Correct |
20 ms |
3524 KB |
Output is correct |
30 |
Correct |
6 ms |
3524 KB |
Output is correct |
31 |
Correct |
5 ms |
3524 KB |
Output is correct |
32 |
Correct |
8 ms |
3524 KB |
Output is correct |
33 |
Execution timed out |
3028 ms |
8284 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |