#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e3+5;
ll n, dp[nx][2], t[nx];
vector<ll> d[nx];
void dfs(int u, int p)
{
dp[u][0]=dp[u][1]=0;
if (t[u]==1) dp[u][1]=1e12;
if (t[u]==2) dp[u][0]=1e12;
for (auto v:d[u]) if (v!=p) dfs(v, u), dp[u][0]+=min(dp[v][0], dp[v][1]+1), dp[u][1]+=min(dp[v][1], dp[v][0]+1);
//cout<<"debug "<<u<<' '<<dp[u][0]<<' '<<dp[u][1]<<'\n';
}
void initialize(int N, std::vector<int> A, std::vector<int> B) {
n=N;
for (int i=0; i<n-1; i++) d[A[i]].push_back(B[i]), d[B[i]].push_back(A[i]);
}
int cat(int v) {
t[v]=1;
dfs(1, 1);
return min(dp[1][0], dp[1][1]);
}
int dog(int v) {
t[v]=2;
dfs(1, 1);
return min(dp[1][0], dp[1][1]);
}
int neighbor(int v) {
t[v]=0;
dfs(1, 1);
return min(dp[1][0], dp[1][1]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
504 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
504 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
6 ms |
336 KB |
Output is correct |
18 |
Correct |
7 ms |
336 KB |
Output is correct |
19 |
Correct |
4 ms |
656 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
9 ms |
544 KB |
Output is correct |
24 |
Correct |
8 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
336 KB |
Output is correct |
29 |
Correct |
11 ms |
588 KB |
Output is correct |
30 |
Correct |
2 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
504 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
6 ms |
336 KB |
Output is correct |
18 |
Correct |
7 ms |
336 KB |
Output is correct |
19 |
Correct |
4 ms |
656 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
9 ms |
544 KB |
Output is correct |
24 |
Correct |
8 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
336 KB |
Output is correct |
29 |
Correct |
11 ms |
588 KB |
Output is correct |
30 |
Correct |
2 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
336 KB |
Output is correct |
33 |
Runtime error |
19 ms |
4432 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |