#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) ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |