#include"catdog.h"
#include<iostream>
#include<vector>
#include<algorithm>
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define semicolon ;
#define ryan bear
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
int n;
vector<int>adj[100010];
int pa[100010];
void dfs(int x)
{
for(int t:adj[x])
{
adj[t].erase(find(all(adj[t]),x));
pa[t]=x;
dfs(t);
}
return;
}
void initialize(int N,vector<int>A,vector<int>B)
{
n=N;
for(int i=0;i<n-1;i++)
adj[A[i]].eb(B[i]),adj[B[i]].eb(A[i]);
dfs(1);
return;
}
int dp[100010][2];
int col[100010];
void calc(int x)
{
for(int t:adj[x])
{
calc(t);
dp[x][0]+=min(dp[t][0],dp[t][1]+1);
dp[x][1]+=min(dp[t][1],dp[t][0]+1);
}
if(col[x]==1)
dp[x][0]=inf;
if(col[x]==2)
dp[x][1]=inf;
return;
}
int cat(int v)
{
col[v]=1;
calc(1);
return min(dp[1][0],dp[1][1]);
}
int dog(int v)
{
col[v]=2;
calc(1);
return min(dp[1][0],dp[1][1]);
}
int neighbor(int v)
{
col[v]=0;
calc(1);
return min(dp[1][0],dp[1][1]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |