Submission #66321

# Submission time Handle Problem Language Result Execution time Memory
66321 2018-08-10T08:35:08 Z zadrga Cats or Dogs (JOI18_catdog) C++14
0 / 100
6 ms 2884 KB
#include "catdog.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (int) (2 * 1e9)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 100111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

int n, ret;
vector<int> adj[maxn];
int col[maxn], cur[maxn];

void DFS(int x, int p){
	for(int v : adj[x]){
		if(v == p)
			continue;

		if(cur[v] == 0)
			cur[v] = cur[x];

		if(cur[x] != cur[v])
			ret++;

		DFS(v, x);
	}
}

int solve(){
	int root = 1;
	for(int i = 1; i <= n; i++){
		cur[i] = col[i];
		if(col[i] != 0)
			root = i;
	}

	ret = 0;
	DFS(root, -1);
	return ret;
}


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

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

int dog(int v){
	col[v] = 2;
	return solve();
}

int neighbor(int v){
	col[v] = 0;
	return solve();
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Incorrect 5 ms 2884 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Incorrect 5 ms 2884 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Incorrect 5 ms 2884 KB Output isn't correct
3 Halted 0 ms 0 KB -