Submission #977528

#TimeUsernameProblemLanguageResultExecution timeMemory
977528vjudge1Cats or Dogs (JOI18_catdog)C++17
38 / 100
3033 ms7884 KiB
#include "catdog.h" #include<bits/stdc++.h> using namespace std; vector<int> v; vector<int>adj[100100]; int state[100100],dp[100100][2]; void dfs(int n,int p){ dp[n][0]=dp[n][1]=0; for(auto i:adj[n]) if(i-p) dfs(i,n), dp[n][0]+=min(dp[i][0],dp[i][1]+1), dp[n][1]+=min(dp[i][0]+1,dp[i][1]); if(state[n]) dp[n][2-state[n]]=1e9; } void initialize(int N, std::vector<int> A, std::vector<int> B) { for(int i=0;i<N-1;i++) adj[A[i]].push_back(B[i]), adj[B[i]].push_back(A[i]); } int cat(int v) { state[v]=1; dfs(1,0); return min(dp[1][0],dp[1][1]); } int dog(int v) { state[v]=2; dfs(1,0); return min(dp[1][0],dp[1][1]); } int neighbor(int v) { state[v]=0; dfs(1,0); 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...