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 "catdog.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
vector<int>adj[100100];
int state[100100],dp[100100][2];
void dfs(int n,int p){
dp[n][0]=dp[n][1]=0;
for(auto i:adj[n]) if(i-p) dfs(i,n),
dp[n][0]+=min(dp[i][0],dp[i][1]+1),
dp[n][1]+=min(dp[i][0]+1,dp[i][1]);
if(state[n])
dp[n][2-state[n]]=1e9;
}
void initialize(int N, std::vector<int> A, std::vector<int> B) {
for(int i=0;i<N-1;i++)
adj[A[i]].push_back(B[i]),
adj[B[i]].push_back(A[i]);
}
int cat(int v) {
state[v]=1;
dfs(1,0);
return min(dp[1][0],dp[1][1]);
}
int dog(int v) {
state[v]=2;
dfs(1,0);
return min(dp[1][0],dp[1][1]);
}
int neighbor(int v) {
state[v]=0;
dfs(1,0);
return min(dp[1][0],dp[1][1]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |