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>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
const int maxn = 1e5+5;
vector<int> adj[maxn];
int dp[3][maxn];
int st[maxn];
int n;
void compute(int u = 1, int p = 0)
{
dp[1][u] = dp[2][u] = 0;
for(int v : adj[u])
{
if(v == p) continue;
compute(v, u);
dp[1][u] += min(dp[1][v], 1+dp[2][v]);
dp[2][u] += min(dp[2][v], 1+dp[1][v]);
}
if(st[u] == 1) dp[2][u] = 1e9;
if(st[u] == 2) dp[1][u] = 1e9;
}
void initialize(int N, vector<int> A, vector<int> B)
{
n = N;
for(int i = 0; i< n-1; i++)
{
adj[A[i]].pb(B[i]);
adj[B[i]].pb(A[i]);
}
}
int cat(int u)
{
st[u] = 1;
compute();
return min(dp[1][1], dp[2][1]);
}
int dog(int u)
{
st[u] = 2;
compute();
return min(dp[1][1], dp[2][1]);
}
int neighbor(int u)
{
st[u] = 0;
compute();
return min(dp[1][1], dp[2][1]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |