Submission #963120

# Submission time Handle Problem Language Result Execution time Memory
963120 2024-04-14T14:34:17 Z pcc Cats or Dogs (JOI18_catdog) C++17
0 / 100
1 ms 348 KB
#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;

const int mxn = 1010;
int x;
vector<int> tree[mxn];
int dp[mxn][3];
int N;
int arr[mxn];

void initialize(int NN, std::vector<int> A, std::vector<int> B) {
	memset(arr,0,sizeof(arr));
	N = NN;
	for(int i = 0;i<N-1;i++){
		int a= A[i],b = B[i];
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	return;
}


void dfs(int now,int par){
	memset(dp[now],0,sizeof(dp[now]));
	for(auto nxt:tree[now]){
		if(nxt == par)continue;
		dfs(nxt,now);
		if(arr[now] == 0)dp[now][0] = min({dp[nxt][0],dp[nxt][1]+1,dp[nxt][2]+1});
		if(arr[now] != 2)dp[now][1] += min({dp[nxt][0],dp[nxt][1],dp[nxt][2]+1});
		if(arr[now] != 1)dp[now][2] += min({dp[nxt][0],dp[nxt][1]+1,dp[nxt][2]});
	}
	if(arr[now]){
		for(int i = 0;i<3;i++){
			if(arr[now] != i)dp[now][i] = mxn;
		}
	}
	return;
}

int answer(){
	dfs(1,1);
	return *min_element(dp[1],dp[1]+3);
}

int cat(int v) {
	arr[v] = 1;
	return answer();
}

int dog(int v) {
	arr[v] = 2;
	return answer();
}

int neighbor(int v) {
	arr[v] = 0;
	return answer();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -