Submission #1110935

#TimeUsernameProblemLanguageResultExecution timeMemory
111093512345678Cats or Dogs (JOI18_catdog)C++17
38 / 100
19 ms4432 KiB
#include "catdog.h" #include <bits/stdc++.h> using namespace std; #define ll long long const int nx=1e3+5; ll n, dp[nx][2], t[nx]; vector<ll> d[nx]; void dfs(int u, int p) { dp[u][0]=dp[u][1]=0; if (t[u]==1) dp[u][1]=1e12; if (t[u]==2) dp[u][0]=1e12; for (auto v:d[u]) if (v!=p) dfs(v, u), dp[u][0]+=min(dp[v][0], dp[v][1]+1), dp[u][1]+=min(dp[v][1], dp[v][0]+1); //cout<<"debug "<<u<<' '<<dp[u][0]<<' '<<dp[u][1]<<'\n'; } void initialize(int N, std::vector<int> A, std::vector<int> B) { n=N; for (int i=0; i<n-1; i++) d[A[i]].push_back(B[i]), d[B[i]].push_back(A[i]); } int cat(int v) { t[v]=1; dfs(1, 1); return min(dp[1][0], dp[1][1]); } int dog(int v) { t[v]=2; dfs(1, 1); return min(dp[1][0], dp[1][1]); } int neighbor(int v) { t[v]=0; dfs(1, 1); return min(dp[1][0], dp[1][1]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...