Submission #79674

#TimeUsernameProblemLanguageResultExecution timeMemory
79674Mahdi_JfriCats or Dogs (JOI18_catdog)C++14
38 / 100
38 ms4892 KiB
#include "catdog.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int maxn = 1e3 + 20; int n , dp[maxn][2] , state[maxn]; vector<int> adj[maxn]; void initialize(int N, std::vector<int> A, std::vector<int> B) { n = N; for(int i = 0; i < n - 1; i++) { int a = A[i] , b = B[i]; a-- , b--; adj[a].pb(b); adj[b].pb(a); } fill(state , state + n , 2); } void dfs(int v , int p = -1) { if(state[v] != 2) dp[v][!state[v]] = n; for(auto u : adj[v]) if(u != p) { dfs(u , v); for(int i = 0; i < 2; i++) dp[v][i] += min(dp[u][!i] + 1 , dp[u][i]); } } int solve() { memset(dp , 0 , sizeof dp); dfs(0); return min(dp[0][0] , dp[0][1]); } int cat(int v) { v--; state[v] = 0; return solve(); } int dog(int v) { v--; state[v] = 1; return solve(); } int neighbor(int v) { v--; state[v] = 2; return solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...