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;
const int N = 1e5 + 7;
int n;
vector<int> adj[N] ;
int hut[N] ;
int x;
int dp[N][3] ;
void initialize(int N, std::vector<int> A, std::vector<int> B)
{
x = A.size();
for(int i = 0 ; i < N - 1;i ++){
adj[A[i]].push_back(B[i]) ;
adj[B[i]].push_back(A[i]) ;
}
return ;
}
int dfs(int x ,int p , int c){
int ret = 0 ;
if(dp[x][c] != -1){
return dp[x][c] ;
}
if(hut[x] && hut[x] != c){
return dp[x][c] = 1e9 ;
}
for(auto u:adj[x] ){
if( u == p)
continue ;
ret += min(dfs(u , x , c) , dfs(u , x, 3 - c) + 1) ;
}
return dp[x][c] = ret ;
}
int answer(){
int ret = 1e9 ;
memset(dp , -1 , sizeof dp) ;
ret = min(ret , dfs(1, 1, 1)) ;
memset(dp , -1 , sizeof dp) ;
ret = min(ret , dfs(1 , 1, 2)) ;
return ret;
}
int cat(int v)
{
hut[v] = 1 ;
return answer() ;
}
int dog(int v)
{
hut[v] = 2 ;
return answer() ;
}
int neighbor(int v)
{
memset(dp , -1 , sizeof dp) ;
hut[v] = 0 ;
return answer();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |