Submission #252909

#TimeUsernameProblemLanguageResultExecution timeMemory
252909test2Cats or Dogs (JOI18_catdog)C++14
0 / 100
4 ms3840 KiB
#include <bits/stdc++.h> #include "catdog.h" using namespace std; const int N = 1e5 + 7; int n; vector<int> adj[N] ; int hut[N] ; int x; int dp[N][3] ; void initialize(int N, std::vector<int> A, std::vector<int> B) { x = A.size(); for(int i = 0 ; i < N - 1;i ++){ adj[A[i]].push_back(B[i]) ; adj[B[i]].push_back(A[i]) ; } return ; } int sub[N] ; int dfs(int x ,int p){ int ret = 0 ; int mask = hut[x] ; int mmask = hut[x] ; for(auto u:adj[x] ){ if( u == p) continue ; dfs(u , x) ; if( (mask|sub[u]) == 3){ ret++ ; } mmask |= sub[u] ; } sub[x] = mmask ; return ret ; } int answer(){ return dfs(1 , 1) ; } int cat(int v) { hut[v] = 1 ; return answer() ; } int dog(int v) { hut[v] = 2 ; return answer() ; } int neighbor(int v) { memset(dp , -1 , sizeof dp) ; hut[v] = 0 ; return answer(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...