답안 #66322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66322 2018-08-10T08:36:21 Z zadrga Cats or Dogs (JOI18_catdog) C++14
0 / 100
4 ms 2680 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;
	if(root != -1)
		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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Incorrect 4 ms 2680 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Incorrect 4 ms 2680 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Incorrect 4 ms 2680 KB Output isn't correct
3 Halted 0 ms 0 KB -