답안 #557849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557849 2022-05-06T07:03:17 Z Koosha_mv Cats or Dogs (JOI18_catdog) C++14
0 / 100
11 ms 23764 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#include "catdog.h"

const int N=1e6+99;

int n,ans,a[N],dp[N];
vector<int> g[N];

void initialize(int _n,vector<int> A,vector<int> B){
	n=_n;
	f(i,0,n-1) g[A[i]].pb(B[i]),g[B[i]].pb(A[i]);		
}
void dfs1(int u,int p){
	int cnt1=0,cnt2=0;
	for(auto v : g[u]){
		if(v==p) continue ;
		dfs1(v,u);
		cnt1+=(dp[v]==1);
		cnt2+=(dp[v]==2);
	}
	if(a[u]==0){
		ans+=min(cnt1,cnt2);
		if(cnt1>cnt2) dp[u]=1;
		if(cnt2>cnt1) dp[u]=2;
	}
	if(a[u]==1){
		ans+=cnt2;
		dp[u]=1;
	}
	if(a[u]==2){
		ans+=cnt1;
		dp[u]=2;
	}
}
int solve(){
	ans=0;
	dfs1(1,1);
	return ans;
}
int cat(int v){
	a[v]=1;	
	return solve();
}
int dog(int v){
	a[v]=2;
	return solve();
}
int neighbor(int v){
	a[v]=0;
	return solve();
}
/*
int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
}*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -