#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] ;
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 dfs(int x ,int p , int c){
int ret = 0 ;
if(hut[x] && hut[x] != c){
return 1e9 ;
}
for(auto u:adj[x] ){
if( u == p)
continue ;
ret += min(dfs(u , x , c) , dfs(u , x, 3 - c) + 1) ;
}
return ret ;
}
int answer(){
int ret = 1e9 ;
memset(dp , -1 , sizeof dp) ;
ret = min(ret , dfs(1, 1, 1)) ;
memset(dp , -1 , sizeof dp) ;
ret = min(ret , dfs(1 , 1, 2)) ;
return ret;
}
int cat(int v)
{
hut[v] = 1 ;
return answer() ;
}
int dog(int v)
{
hut[v] = 2 ;
return answer() ;
}
int neighbor(int v)
{
hut[v] = 0 ;
return answer();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Correct |
4 ms |
3072 KB |
Output is correct |
3 |
Correct |
5 ms |
3072 KB |
Output is correct |
4 |
Correct |
4 ms |
3072 KB |
Output is correct |
5 |
Correct |
6 ms |
3072 KB |
Output is correct |
6 |
Correct |
7 ms |
3072 KB |
Output is correct |
7 |
Correct |
4 ms |
3072 KB |
Output is correct |
8 |
Correct |
4 ms |
3072 KB |
Output is correct |
9 |
Correct |
5 ms |
3072 KB |
Output is correct |
10 |
Correct |
4 ms |
3072 KB |
Output is correct |
11 |
Correct |
6 ms |
3072 KB |
Output is correct |
12 |
Correct |
3 ms |
3072 KB |
Output is correct |
13 |
Correct |
3 ms |
3072 KB |
Output is correct |
14 |
Correct |
4 ms |
3072 KB |
Output is correct |
15 |
Correct |
4 ms |
3072 KB |
Output is correct |
16 |
Correct |
4 ms |
3072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Correct |
4 ms |
3072 KB |
Output is correct |
3 |
Correct |
5 ms |
3072 KB |
Output is correct |
4 |
Correct |
4 ms |
3072 KB |
Output is correct |
5 |
Correct |
6 ms |
3072 KB |
Output is correct |
6 |
Correct |
7 ms |
3072 KB |
Output is correct |
7 |
Correct |
4 ms |
3072 KB |
Output is correct |
8 |
Correct |
4 ms |
3072 KB |
Output is correct |
9 |
Correct |
5 ms |
3072 KB |
Output is correct |
10 |
Correct |
4 ms |
3072 KB |
Output is correct |
11 |
Correct |
6 ms |
3072 KB |
Output is correct |
12 |
Correct |
3 ms |
3072 KB |
Output is correct |
13 |
Correct |
3 ms |
3072 KB |
Output is correct |
14 |
Correct |
4 ms |
3072 KB |
Output is correct |
15 |
Correct |
4 ms |
3072 KB |
Output is correct |
16 |
Correct |
4 ms |
3072 KB |
Output is correct |
17 |
Execution timed out |
3055 ms |
3072 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Correct |
4 ms |
3072 KB |
Output is correct |
3 |
Correct |
5 ms |
3072 KB |
Output is correct |
4 |
Correct |
4 ms |
3072 KB |
Output is correct |
5 |
Correct |
6 ms |
3072 KB |
Output is correct |
6 |
Correct |
7 ms |
3072 KB |
Output is correct |
7 |
Correct |
4 ms |
3072 KB |
Output is correct |
8 |
Correct |
4 ms |
3072 KB |
Output is correct |
9 |
Correct |
5 ms |
3072 KB |
Output is correct |
10 |
Correct |
4 ms |
3072 KB |
Output is correct |
11 |
Correct |
6 ms |
3072 KB |
Output is correct |
12 |
Correct |
3 ms |
3072 KB |
Output is correct |
13 |
Correct |
3 ms |
3072 KB |
Output is correct |
14 |
Correct |
4 ms |
3072 KB |
Output is correct |
15 |
Correct |
4 ms |
3072 KB |
Output is correct |
16 |
Correct |
4 ms |
3072 KB |
Output is correct |
17 |
Execution timed out |
3055 ms |
3072 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |