Submission #778713

#TimeUsernameProblemLanguageResultExecution timeMemory
778713Ahmed57Cats or Dogs (JOI18_catdog)C++17
38 / 100
3066 ms7212 KiB
#include "catdog.h" #include <bits/stdc++.h> using namespace std; vector<int> adj[100001]; bool ss = 0; void initialize(int N,vector<int> A,vector<int> B){ if(N==1)ss = 1; for(int i = 0;i<N-1;i++){ adj[A[i]].push_back(B[i]); adj[B[i]].push_back(A[i]); } } int R[100001],B[100001]; int col[100001]; void solve(int i,int pr){ R[i] = 0;B[i] = 0; for(auto j:adj[i]){ if(j==pr)continue; solve(j,i); R[i] += min(R[j],B[j]+1); B[i] += min(R[j]+1,B[j]); } if(col[i]==1){ B[i] = 1e9; }if(col[i]==2){ R[i] = 1e9; } } int cat(int v){ if(ss)return 0; col[v] = 1; solve(1,0); return min(R[1],B[1]); }int dog(int v){ if(ss)return 0; col[v] = 2; solve(1,0); return min(R[1],B[1]); }int neighbor(int v){ if(ss)return 0; col[v] = 0; solve(1,0); return min(R[1],B[1]); }/* int main(){ int N = 5;vector<int>A = {1,2,2,4}; vector<int> BB = {2,3,4,5}; initialize(N,A,BB); cout<<cat(3)<<endl; cout<<dog(5)<<endl; cout<<dog(1)<<endl; cout<<cat(2)<<endl; cout<<neighbor(2)<<endl; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...