Submission #122170

# Submission time Handle Problem Language Result Execution time Memory
122170 2019-06-27T18:39:02 Z wilwxk Cats or Dogs (JOI18_catdog) C++11
38 / 100
3000 ms 7528 KB
#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+5;
vector<int> g[MAXN];
int dp[MAXN][2];
int cor[MAXN];
int n;

void dfs(int cur, int p) {
	dp[cur][0]=dp[cur][1]=0;
	for(auto viz : g[cur]) {
		if(viz==p) continue;
		dfs(viz, cur);
		dp[cur][0]+=min(dp[viz][0], dp[viz][1]+1);
		dp[cur][1]+=min(dp[viz][1], dp[viz][0]+1);
	}
	if(cor[cur]!=-1) dp[cur][!cor[cur]]=n+n;
}

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

int cat(int v) {
	cor[v]=0;
	dfs(1, 1);
	return min(dp[1][0], dp[1][1]);
}

int dog(int v) {
	cor[v]=1;
	dfs(1, 1);
	return min(dp[1][0], dp[1][1]);
}

int neighbor(int v) {
	cor[v]=-1;
	dfs(1, 1);
	return min(dp[1][0], dp[1][1]);
}

Compilation message

catdog.cpp: In function 'void initialize(int, std::vector<int>, std::vector<int>)':
catdog.cpp:24:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<A.size(); i++) g[A[i]].push_back(B[i]), g[B[i]].push_back(A[i]);
               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3072 KB Output is correct
2 Correct 4 ms 3072 KB Output is correct
3 Correct 4 ms 3072 KB Output is correct
4 Correct 4 ms 3072 KB Output is correct
5 Correct 4 ms 3072 KB Output is correct
6 Correct 4 ms 3072 KB Output is correct
7 Correct 5 ms 3072 KB Output is correct
8 Correct 4 ms 3072 KB Output is correct
9 Correct 4 ms 3072 KB Output is correct
10 Correct 4 ms 3072 KB Output is correct
11 Correct 4 ms 3072 KB Output is correct
12 Correct 4 ms 3072 KB Output is correct
13 Correct 4 ms 3072 KB Output is correct
14 Correct 4 ms 3072 KB Output is correct
15 Correct 4 ms 3072 KB Output is correct
16 Correct 4 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3072 KB Output is correct
2 Correct 4 ms 3072 KB Output is correct
3 Correct 4 ms 3072 KB Output is correct
4 Correct 4 ms 3072 KB Output is correct
5 Correct 4 ms 3072 KB Output is correct
6 Correct 4 ms 3072 KB Output is correct
7 Correct 5 ms 3072 KB Output is correct
8 Correct 4 ms 3072 KB Output is correct
9 Correct 4 ms 3072 KB Output is correct
10 Correct 4 ms 3072 KB Output is correct
11 Correct 4 ms 3072 KB Output is correct
12 Correct 4 ms 3072 KB Output is correct
13 Correct 4 ms 3072 KB Output is correct
14 Correct 4 ms 3072 KB Output is correct
15 Correct 4 ms 3072 KB Output is correct
16 Correct 4 ms 3072 KB Output is correct
17 Correct 10 ms 3072 KB Output is correct
18 Correct 12 ms 3200 KB Output is correct
19 Correct 8 ms 3072 KB Output is correct
20 Correct 4 ms 3072 KB Output is correct
21 Correct 6 ms 3072 KB Output is correct
22 Correct 6 ms 3072 KB Output is correct
23 Correct 14 ms 3072 KB Output is correct
24 Correct 12 ms 3072 KB Output is correct
25 Correct 7 ms 3072 KB Output is correct
26 Correct 6 ms 3044 KB Output is correct
27 Correct 5 ms 3072 KB Output is correct
28 Correct 7 ms 3200 KB Output is correct
29 Correct 18 ms 3200 KB Output is correct
30 Correct 5 ms 3072 KB Output is correct
31 Correct 5 ms 3072 KB Output is correct
32 Correct 6 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3072 KB Output is correct
2 Correct 4 ms 3072 KB Output is correct
3 Correct 4 ms 3072 KB Output is correct
4 Correct 4 ms 3072 KB Output is correct
5 Correct 4 ms 3072 KB Output is correct
6 Correct 4 ms 3072 KB Output is correct
7 Correct 5 ms 3072 KB Output is correct
8 Correct 4 ms 3072 KB Output is correct
9 Correct 4 ms 3072 KB Output is correct
10 Correct 4 ms 3072 KB Output is correct
11 Correct 4 ms 3072 KB Output is correct
12 Correct 4 ms 3072 KB Output is correct
13 Correct 4 ms 3072 KB Output is correct
14 Correct 4 ms 3072 KB Output is correct
15 Correct 4 ms 3072 KB Output is correct
16 Correct 4 ms 3072 KB Output is correct
17 Correct 10 ms 3072 KB Output is correct
18 Correct 12 ms 3200 KB Output is correct
19 Correct 8 ms 3072 KB Output is correct
20 Correct 4 ms 3072 KB Output is correct
21 Correct 6 ms 3072 KB Output is correct
22 Correct 6 ms 3072 KB Output is correct
23 Correct 14 ms 3072 KB Output is correct
24 Correct 12 ms 3072 KB Output is correct
25 Correct 7 ms 3072 KB Output is correct
26 Correct 6 ms 3044 KB Output is correct
27 Correct 5 ms 3072 KB Output is correct
28 Correct 7 ms 3200 KB Output is correct
29 Correct 18 ms 3200 KB Output is correct
30 Correct 5 ms 3072 KB Output is correct
31 Correct 5 ms 3072 KB Output is correct
32 Correct 6 ms 3072 KB Output is correct
33 Execution timed out 3042 ms 7528 KB Time limit exceeded
34 Halted 0 ms 0 KB -