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 = 100001;
int n;
vector<int> adj[N];
int dp[N][3];
int val[N];
void dfs(int u, int p){
dp[u][1] = 0;
dp[u][2] = 0;
for(int v : adj[u]){
if(v != p){
dfs(v, u);
dp[u][1] += min(dp[v][0], dp[v][1]);
dp[u][2] += min(dp[v][0], dp[v][2]);
}
}
if(val[u] == 1){
dp[u][2] = 1e9;
}
if(val[u] == 2){
dp[u][1] = 1e9;
}
dp[u][0] = min(dp[u][1], dp[u][2]) + 1;
}
int solve(){
dfs(1, 0);
return dp[1][0] - 1;
}
void initialize(int N, vector<int> a, vector<int> b){
n = N;
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 u){
val[u] = 1;
return solve();
}
int dog(int u){
val[u] = 2;
return solve();
}
int neighbor(int u){
val[u] = 0;
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... |