Submission #110634

# Submission time Handle Problem Language Result Execution time Memory
110634 2019-05-11T18:08:44 Z gs14004 Cats or Dogs (JOI18_catdog) C++17
38 / 100
3000 ms 10588 KB
#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int inf = 1e9;

int n, a[MAXN];
vector<int> gph[MAXN];
int dp[MAXN][3], par[MAXN];

void dfs(int x){
	for(auto &i : gph[x]){
		gph[i].erase(find(gph[i].begin(), gph[i].end(), x));
		par[i] = x;
		dfs(i);
	}
}

void initialize(int N, std::vector<int> A, std::vector<int> B) {
	n = N;
	for(int i=0; i<n-1; i++){
		gph[A[i]].push_back(B[i]);
		gph[B[i]].push_back(A[i]);
	}
	dfs(1);
}

void cons(int v){
	memset(dp[v], 0, sizeof(dp[v]));
	for(auto &i : gph[v]){
		dp[v][0] += min({dp[i][0], dp[i][1] + 1, dp[i][2] + 1});
		dp[v][1] += min({dp[i][0], dp[i][1], dp[i][2] + 1});
		dp[v][2] += min({dp[i][0], dp[i][1] + 1, dp[i][2]});
	}
	if(a[v] == 1) dp[v][0] = dp[v][2] = 1e9;
	if(a[v] == 2) dp[v][0] = dp[v][1] = 1e9;
}

int cat(int v) {
	a[v] = 1;
	while(v){
		cons(v);
		v = par[v];
	}
	return min({dp[1][0], dp[1][1], dp[1][2]});
}

int dog(int v) {
	a[v] = 2;
	while(v){
		cons(v);
		v = par[v];
	}
	return min({dp[1][0], dp[1][1], dp[1][2]});
}

int neighbor(int v) {
	a[v] = 0;
	while(v){
		cons(v);
		v = par[v];
	}
	return min({dp[1][0], dp[1][1], dp[1][2]});
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 5 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 5 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 5 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct
11 Correct 5 ms 2688 KB Output is correct
12 Correct 4 ms 2688 KB Output is correct
13 Correct 5 ms 2688 KB Output is correct
14 Correct 5 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 5 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 5 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 5 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 5 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct
11 Correct 5 ms 2688 KB Output is correct
12 Correct 4 ms 2688 KB Output is correct
13 Correct 5 ms 2688 KB Output is correct
14 Correct 5 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 5 ms 2688 KB Output is correct
17 Correct 7 ms 2816 KB Output is correct
18 Correct 5 ms 2688 KB Output is correct
19 Correct 6 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 5 ms 2688 KB Output is correct
22 Correct 5 ms 2688 KB Output is correct
23 Correct 5 ms 2688 KB Output is correct
24 Correct 16 ms 2788 KB Output is correct
25 Correct 5 ms 2688 KB Output is correct
26 Correct 5 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 5 ms 2816 KB Output is correct
29 Correct 9 ms 2816 KB Output is correct
30 Correct 6 ms 2688 KB Output is correct
31 Correct 5 ms 2816 KB Output is correct
32 Correct 6 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 5 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 5 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 5 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct
11 Correct 5 ms 2688 KB Output is correct
12 Correct 4 ms 2688 KB Output is correct
13 Correct 5 ms 2688 KB Output is correct
14 Correct 5 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 5 ms 2688 KB Output is correct
17 Correct 7 ms 2816 KB Output is correct
18 Correct 5 ms 2688 KB Output is correct
19 Correct 6 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 5 ms 2688 KB Output is correct
22 Correct 5 ms 2688 KB Output is correct
23 Correct 5 ms 2688 KB Output is correct
24 Correct 16 ms 2788 KB Output is correct
25 Correct 5 ms 2688 KB Output is correct
26 Correct 5 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 5 ms 2816 KB Output is correct
29 Correct 9 ms 2816 KB Output is correct
30 Correct 6 ms 2688 KB Output is correct
31 Correct 5 ms 2816 KB Output is correct
32 Correct 6 ms 2688 KB Output is correct
33 Correct 610 ms 6988 KB Output is correct
34 Correct 189 ms 6908 KB Output is correct
35 Correct 758 ms 6128 KB Output is correct
36 Correct 1052 ms 9904 KB Output is correct
37 Correct 28 ms 4864 KB Output is correct
38 Correct 1042 ms 10424 KB Output is correct
39 Correct 1059 ms 10468 KB Output is correct
40 Correct 1138 ms 10472 KB Output is correct
41 Correct 1281 ms 10472 KB Output is correct
42 Correct 1831 ms 10460 KB Output is correct
43 Correct 1132 ms 10588 KB Output is correct
44 Correct 1598 ms 10568 KB Output is correct
45 Correct 2013 ms 10472 KB Output is correct
46 Correct 1094 ms 10472 KB Output is correct
47 Correct 1069 ms 10504 KB Output is correct
48 Execution timed out 3034 ms 8060 KB Time limit exceeded
49 Halted 0 ms 0 KB -