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;
typedef int ll;
typedef vector<int> vll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
ll N;
vector<ll> g[1010];
ll dp[1010][2],col[1010];
void dfs(ll x,ll from){
rep(k,2)dp[x][k]=1e9;
if(col[x]!=1)dp[x][0]=0;
if(col[x]!=0)dp[x][1]=0;
for(auto y:g[x])if(y!=from){
dfs(y,x);
dp[x][0]+=min(dp[y][0],dp[y][1]+1);
dp[x][1]+=min(dp[y][0]+1,dp[y][1]);
}
}
ll solve(){
dfs(1,0);
return min(dp[1][0],dp[1][1]);
}
ll cat(int v){
col[v]=0;
return solve();
}
ll dog(int v){
col[v]=1;
return solve();
}
ll neighbor(int v){
col[v]=2;
return solve();
}
void initialize(ll n,vll a,vll b){
rep(i,n-1){
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
for(int i=1;i<=n;i++)col[i]=2;
}
/*int main(){
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |