Submission #388094

#TimeUsernameProblemLanguageResultExecution timeMemory
388094mohamedsobhi777Cats or Dogs (JOI18_catdog)C++14
0 / 100
0 ms204 KiB
#include<bits/stdc++.h> #include "catdog.h" using namespace std ; int x; const int MX = 1000 + 7 ; int val[MX] ; vector<int> adj[MX] ; int root ; void initialize(int N, std::vector<int> A, std::vector<int> B) { for(int i = 0 ;i < N ;++ i){ adj[A[i]].push_back(B[i]) ; adj[B[i]].push_back(A[i]) ; } for(int i =1 ;i <= N ; ++ i){ if(adj[i].size() == 1){ root = i ; } } } int dfs(int x, int p , int lst = 0){ int ret = 0 ; if(val[x] && lst && val[x] != lst){ ++ret ; } for(auto u : adj[x]){ if(u == p)continue ; ret += dfs(u , x , (val[x]?val[x]:lst) ) ; } return ret; } int cat(int v) { val[v] = 1; return dfs(root , root ) ; } int dog(int v) { val[v] = 2; return dfs(root , root ) ; } int neighbor(int v) { val[v] =0 ; return dfs(root , root ) ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...