This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "catdog.h"
using namespace std ; 
int x;
const int MX = 1000 + 7 ; 
int val[MX] ;
vector<int> adj[MX] ;
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]) ; 
       }
}
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(1 , 1) ; 
}
int dog(int v)
{
       val[v] = 2; 
       return dfs(1 , 1) ; 
}
int neighbor(int v)
{
       val[v] =0 ; 
       return dfs(1 , 1) ;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |