Submission #598270

# Submission time Handle Problem Language Result Execution time Memory
598270 2022-07-17T21:39:39 Z penguinhacker Cats or Dogs (JOI18_catdog) C++17
38 / 100
3000 ms 7208 KB
#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN=1e5, INF=1e9;
int n, type[mxN], dp[mxN][2];
vector<int> adj[mxN];

void initialize(int N, vector<int> A, vector<int> B) {
	n=N;
	for (int i=0; i<n-1; ++i) {
		int u=A[i]-1, v=B[i]-1;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
}

void dfs(int u=0, int p=-1) {
	dp[u][0]=type[u]!=2?0:INF;
	dp[u][1]=type[u]!=1?0:INF;
	for (int v : adj[u])
		if (v!=p) {
			dfs(v, u);
			for (int i : {0, 1})
				dp[u][i]=min(min(dp[u][i]+dp[v][i], dp[u][i]+dp[v][i^1]+1), INF);
		}
}

int solve() {
	dfs();
	return min(dp[0][0], dp[0][1]);
}

int cat(int v) {
	type[v-1]=1;
	return solve();
}

int dog(int v) {
	type[v-1]=2;
	return solve();
}

int neighbor(int v) {
	type[v-1]=0;
	return solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2660 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2664 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2660 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2664 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 9 ms 2664 KB Output is correct
18 Correct 12 ms 2644 KB Output is correct
19 Correct 8 ms 2644 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 13 ms 2644 KB Output is correct
24 Correct 11 ms 2668 KB Output is correct
25 Correct 7 ms 2668 KB Output is correct
26 Correct 5 ms 2660 KB Output is correct
27 Correct 3 ms 2644 KB Output is correct
28 Correct 5 ms 2644 KB Output is correct
29 Correct 14 ms 2664 KB Output is correct
30 Correct 3 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 3 ms 2700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2660 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2664 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 9 ms 2664 KB Output is correct
18 Correct 12 ms 2644 KB Output is correct
19 Correct 8 ms 2644 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 13 ms 2644 KB Output is correct
24 Correct 11 ms 2668 KB Output is correct
25 Correct 7 ms 2668 KB Output is correct
26 Correct 5 ms 2660 KB Output is correct
27 Correct 3 ms 2644 KB Output is correct
28 Correct 5 ms 2644 KB Output is correct
29 Correct 14 ms 2664 KB Output is correct
30 Correct 3 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 3 ms 2700 KB Output is correct
33 Execution timed out 3053 ms 7208 KB Time limit exceeded
34 Halted 0 ms 0 KB -