제출 #388118

#제출 시각아이디문제언어결과실행 시간메모리
388118mohamedsobhi777Cats or Dogs (JOI18_catdog)C++14
8 / 100
14 ms664 KiB
#include <bits/stdc++.h> #include "catdog.h" using namespace std; int x; const int MX = 10000 + 7; int val[MX]; vector<int> adj[MX]; int dp[MX][2] ; void initialize(int N, std::vector<int> A, std::vector<int> B) { x = N ; for (int i = 0; i < N; ++i) { adj[A[i]].push_back(B[i]); adj[B[i]].push_back(A[i]); } fill(val + 1, val + N + 1, 2) ; } void dfs(int x, int p) { if(val[x]!=2)dp[x][ !val[x] ] = MX ; for(auto u : adj[x]){ if(u == p)continue; dfs(u , x) ; dp[x][0] += min(dp[u][0] ,dp[u][1] + 1) ; dp[x][1] += min(dp[u][1] ,dp[u][0] + 1) ; } } int solve(){ memset(dp ,0 ,sizeof dp) ; dfs(1 , 1) ; return min(dp[1][0] , dp[1][1]) ; } int cat(int v) { val[v] = 0; return solve() ; } int dog(int v) { val[v] = 1; return solve() ; } int neighbor(int v) { val[v] = 2; return solve() ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...