#include "catdog.h"
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
using namespace std ;
const int maxn = 1e6 + 10 , inf= 2e9 , mod = 1e9 + 7 , sq = 360 ,MX = 20000 ;
int dp[maxn][2] , mark[maxn];
vector <int> G[maxn] ;
void dfs(int v, int p =0 ){
dp[v][0] = dp[v][1]= 0;
if(mark[v]==1)dp[v][1] = inf ;
if(mark[v]==2)dp[v][0] = inf ;
for(int u : G[v]){
if(u == p)continue ;
dfs(u , v);
dp[v][0]= dp[v][0] + min(dp[u][1] + 1 , dp[u][0]) ;
dp[v][1]= dp[v][1] + min(dp[u][0] + 1 , dp[u][1]) ;
}
}
void initialize(int N , vector <int> a , vector <int> b){
rep(i , 0 , N-2){
G[a[i]+1].pb(b[i]+1) ;
G[b[i]+1].pb(a[i]+1) ;
}
}
int cat(int v){
mark[v]=1;
dfs(1);
return min(dp[v][0] , dp[v][1]) ;
}
int dog(int v){
mark[v]=2;
dfs(1) ;
return min(dp[1][0] , dp[1][1]) ;
}
int neighbor(int v){
mark[v] = 0 ;
dfs(1) ;
return min(dp[1][0] , dp[1][1]) ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
27480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
27480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
27480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |