This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "catdog.h"
using namespace std;
int x;
const int MX = 1000 + 7;
int val[MX];
vector<int> adj[MX];
int root;
int dp[MX][2] ;
void initialize(int N, std::vector<int> A, std::vector<int> B)
{
x = N ;
for (int i = 0; i < N; ++i)
{
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
fill(val + 1, val + N + 1, 2) ;
}
void dfs(int x, int p)
{
if(val[x]!=2)dp[x][ !val[x] ] = MX ;
for(auto u : adj[x]){
if(u == p)continue;
dfs(u , x) ;
dp[x][0] += min(dp[u][0] ,dp[u][1] + 1) ;
dp[x][1] += min(dp[u][1] ,dp[u][0] + 1) ;
}
}
int solve(){
memset(dp ,0 ,sizeof dp) ;
dfs(1 , 1) ;
return min(dp[1][0] , dp[1][1]) ;
}
int cat(int v)
{
val[v] = 0;
return solve() ;
}
int dog(int v)
{
val[v] = 1;
return solve() ;
}
int neighbor(int v)
{
val[v] = 2;
return solve() ;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |