#include <vector>
#include <bits/stdc++.h>
#include <iostream>
#include "catdog.h"
using namespace std;
const int NMAX = 1e5;
const int INF = 1e9;
int x , n;
vector<int> adj[NMAX+1];
int stat[NMAX+1];
int dp[3][NMAX+1];
void dfs (int nod = 1, int par = 0)
{
dp[stat[nod]][nod] = 0;
for (int &to : adj[nod])
{
if (to != par)
{
dfs(to, nod);
dp[stat[nod]][nod] += min(min(dp[2][to] , dp[stat[nod]][to]) , dp[stat[nod]^1][to]+1);
}
}
for (int i = 0; i < 3; i++)
{
if (i != stat[nod])
dp[i][nod] = INF;
}
}
void initialize(int N, std::vector<int> A, std::vector<int> B) {
x = A.size();
n = N;
for (int i = 0; i < n-1; i++)
{
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
for (int i = 1; i <= n; i++)
{
stat[i] = 2;
}
}
int cat(int v) {
stat[v] = 1;
dfs();
return min({dp[0][1], dp[1][1], dp[2][1]});
}
int dog(int v) {
stat[v] = 0;
dfs();
return min({dp[0][1], dp[1][1], dp[2][1]});
}
int neighbor(int v) {
stat[v] = 2;
dfs();
return min({dp[0][1], dp[1][1], dp[2][1]});
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
3932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
3932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
3932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |