#include <bits/stdc++.h>
//#include "catdog.h"
using namespace std;
const int inf = 1e9;
vector<int> a;
vector<vector<int>> g;
vector<vector<int>> dp;
void initialize(int N, vector<int> A, vector<int> B)
{
g = vector<vector<int>>(N + 1);
dp = vector<vector<int>>(N + 1, vector<int>(2));
a = vector<int>(N + 1, 2);
for (int i = 1; i <= N; ++i)
{
g[A[i]].emplace_back(B[i]);
g[B[i]].emplace_back(A[i]);
}
}
void dfs(int node, int parent)
{
for (int i = 0; i < 2; ++i)
{
dp[node][i] = inf;
}
for (auto i : g[node])
{
if (i != parent)
{
dfs(i, node);
for (int j = 0; j < 2; ++j)
{
dp[node][j] = min({dp[node][j], dp[i][j], dp[i][j ^ 1] + 1});
}
}
}
if (a[node] != 2)
{
dp[node][a[node] ^ 1] = inf;
}
}
int cat(int v)
{
a[v] = 0;
dfs(1, 0);
return min(dp[1][0], dp[1][1]);
}
int dog(int v)
{
a[v] = 1;
dfs(1, 0);
return min(dp[1][0], dp[1][1]);
}
int neighbor(int v)
{
a[v] = 2;
dfs(1, 0);
return min(dp[1][0], dp[1][1]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |