#include "catdog.h"
#include <array>
using namespace std;
const int MAXN = 1e5;
static vector<int> E[MAXN+2];
static int pet[MAXN+2];
static int N;
void initialize(int nn, vector<int> A, vector<int> B)
{
N = nn;
for (int i = 0; i < N - 1; ++i)
{
//printf("(%d %d)\n", A[i], B[i]);
E[A[i]].push_back(B[i]);
E[B[i]].push_back(A[i]);
}
}
typedef array<int, 3> dpt;
dpt rec(int x, int p)
{
/*vector<dpt> dd(v);
for (int i = 0; i < E[x].size(); ++i)
{
int v = E[x][i];
if (v != p)
dd[i] = rec(v, p);
}*/
dpt res;
res[0] = 0;
res[1] = 0;
res[2] = 0;
for (int i = 0; i < E[x].size(); ++i)
{
int v = E[x][i];
if (v != p)
{
dpt dp = rec(v, x);
res[0] += min(dp[0], min(dp[1], dp[2]) + 1);
res[1] += min(dp[1], min(dp[0], dp[2] + 1));
res[2] += min(dp[2], min(dp[0], dp[1] + 1));
res[0] = min(res[0], int(1e8));
res[1] = min(res[1], int(1e8));
res[2] = min(res[2], int(1e8));
}
}
if (pet[x] == 1)
{
res[0] = int(1e8);
res[2] = int(1e8);
}
else if (pet[x] == 2)
{
res[0] = int(1e8);
res[1] = int(1e8);
}
//printf("%d %d (%d %d %d)\n", x, p, res[0], res[1], res[2]);
return res;
}
static int solve()
{
dpt res = rec(1, -1);
int ans = min(res[0], min(res[1], res[2]));;
//printf("ans = %d\n", ans);
return ans;
}
int cat(int v)
{
pet[v] = 1;
return solve();
}
int dog(int v)
{
pet[v] = 2;
return solve();
}
int neighbor(int v)
{
pet[v] = 0;
return solve();
}
Compilation message
catdog.cpp: In function 'dpt rec(int, int)':
catdog.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i = 0; i < E[x].size(); ++i)
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2668 KB |
Output is correct |
6 |
Correct |
2 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
2 ms |
2668 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
2 ms |
2668 KB |
Output is correct |
12 |
Correct |
2 ms |
2668 KB |
Output is correct |
13 |
Correct |
2 ms |
2668 KB |
Output is correct |
14 |
Correct |
2 ms |
2668 KB |
Output is correct |
15 |
Correct |
2 ms |
2668 KB |
Output is correct |
16 |
Correct |
2 ms |
2668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2668 KB |
Output is correct |
6 |
Correct |
2 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
2 ms |
2668 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
2 ms |
2668 KB |
Output is correct |
12 |
Correct |
2 ms |
2668 KB |
Output is correct |
13 |
Correct |
2 ms |
2668 KB |
Output is correct |
14 |
Correct |
2 ms |
2668 KB |
Output is correct |
15 |
Correct |
2 ms |
2668 KB |
Output is correct |
16 |
Correct |
2 ms |
2668 KB |
Output is correct |
17 |
Correct |
15 ms |
2668 KB |
Output is correct |
18 |
Correct |
19 ms |
2776 KB |
Output is correct |
19 |
Correct |
10 ms |
2668 KB |
Output is correct |
20 |
Correct |
2 ms |
2668 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
5 ms |
2668 KB |
Output is correct |
23 |
Correct |
22 ms |
2668 KB |
Output is correct |
24 |
Correct |
18 ms |
2668 KB |
Output is correct |
25 |
Correct |
9 ms |
2668 KB |
Output is correct |
26 |
Correct |
5 ms |
2668 KB |
Output is correct |
27 |
Correct |
4 ms |
2668 KB |
Output is correct |
28 |
Correct |
6 ms |
2796 KB |
Output is correct |
29 |
Correct |
21 ms |
2796 KB |
Output is correct |
30 |
Correct |
5 ms |
2668 KB |
Output is correct |
31 |
Correct |
4 ms |
2668 KB |
Output is correct |
32 |
Correct |
6 ms |
2668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2668 KB |
Output is correct |
6 |
Correct |
2 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
2 ms |
2668 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
2 ms |
2668 KB |
Output is correct |
12 |
Correct |
2 ms |
2668 KB |
Output is correct |
13 |
Correct |
2 ms |
2668 KB |
Output is correct |
14 |
Correct |
2 ms |
2668 KB |
Output is correct |
15 |
Correct |
2 ms |
2668 KB |
Output is correct |
16 |
Correct |
2 ms |
2668 KB |
Output is correct |
17 |
Correct |
15 ms |
2668 KB |
Output is correct |
18 |
Correct |
19 ms |
2776 KB |
Output is correct |
19 |
Correct |
10 ms |
2668 KB |
Output is correct |
20 |
Correct |
2 ms |
2668 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
5 ms |
2668 KB |
Output is correct |
23 |
Correct |
22 ms |
2668 KB |
Output is correct |
24 |
Correct |
18 ms |
2668 KB |
Output is correct |
25 |
Correct |
9 ms |
2668 KB |
Output is correct |
26 |
Correct |
5 ms |
2668 KB |
Output is correct |
27 |
Correct |
4 ms |
2668 KB |
Output is correct |
28 |
Correct |
6 ms |
2796 KB |
Output is correct |
29 |
Correct |
21 ms |
2796 KB |
Output is correct |
30 |
Correct |
5 ms |
2668 KB |
Output is correct |
31 |
Correct |
4 ms |
2668 KB |
Output is correct |
32 |
Correct |
6 ms |
2668 KB |
Output is correct |
33 |
Execution timed out |
3071 ms |
7000 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |