This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 20;
int n , dp[maxn][2] , state[maxn];
vector<int> adj[maxn];
void initialize(int N, std::vector<int> A, std::vector<int> B)
{
n = N;
for(int i = 0; i < n - 1; i++)
{
int a = A[i] , b = B[i];
a-- , b--;
adj[a].pb(b);
adj[b].pb(a);
}
fill(state , state + n , 2);
}
void dfs(int v , int p = -1)
{
if(state[v] != 2)
dp[v][!state[v]] = n;
for(auto u : adj[v])
if(u != p)
{
dfs(u , v);
for(int i = 0; i < 2; i++)
dp[v][i] += min(dp[u][!i] + 1 , dp[u][i]);
}
}
int solve()
{
memset(dp , 0 , sizeof dp);
dfs(0);
return min(dp[0][0] , dp[0][1]);
}
int cat(int v)
{
v--;
state[v] = 0;
return solve();
}
int dog(int v)
{
v--;
state[v] = 1;
return solve();
}
int neighbor(int v)
{
v--;
state[v] = 2;
return solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |