#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] ;
void dfz(int x, int p ){
sub[x] = hut[x] ;
for(auto u : adj[x]){
if( u == p)
continue ;
dfz(u , x) ;
sub[x] |= sub[u] ;
}
return ;
}
int dfs(int x ,int p){
if( x != p && sub[x] != 3 && (hut[x]|hut[p]) == 3 ){
return 1 ;
}
int ret = 0 ;
for(auto u:adj[x] ){
if( u == p)
continue ;
ret += dfs(u , x) ;
}
return ret ;
}
int answer(){
dfz(1 , 1) ;
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 time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3840 KB |
Output is correct |
2 |
Incorrect |
3 ms |
3840 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3840 KB |
Output is correct |
2 |
Incorrect |
3 ms |
3840 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3840 KB |
Output is correct |
2 |
Incorrect |
3 ms |
3840 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |