//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "catdog.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
vi adj[MAXN];
int cur[MAXN], dp[MAXN][2], val[MAXN];
void initialize(int N, vi A, vi B) {
for (int i = 0; i+1 < N; i++) {
adj[A[i]].pb(B[i]);
adj[B[i]].pb(A[i]);
}
}
void dfs(int u, int p) {
if (cur[u] == 1)
dp[u][1] = INF;
else if (cur[u] == 2)
dp[u][0] = INF;
int a = 0, b = 0;
for (int v: adj[u]) {
if (v == p)
continue;
dfs(v, u);
if (cur[u] == 1)
dp[u][0] += min(dp[v][0], dp[v][1] + 1);
else if (cur[u] == 2)
dp[u][1] += min(dp[v][1], dp[v][0] + 1);
else {
a += min(dp[v][0], dp[v][1] + 1);
b += min(dp[v][1], dp[v][0] + 1);
}
}
if (cur[u] == 0)
dp[u][0] = a, dp[u][1] = b;
}
int cat(int v) {
cur[v] = 1;
mem(dp, 0);
dfs(0, -1);
return min(dp[0][0], dp[0][1]);
}
int dog(int v) {
cur[v] = 2;
mem(dp, 0);
dfs(0, -1);
return min(dp[0][0], dp[0][1]);
}
int neighbor(int v) {
cur[v] = 0;
mem(dp, 0);
dfs(0, -1);
return min(dp[0][0], dp[0][1]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
3448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
3448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
3448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |