/*
doing virtual contest
start: 10:00
finish: 14:00
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
vector<vector<int>> g;
vector<int> type;
void initialize(int n_, vector<int> a, vector<int> b) {
n = n_;
g = vector<vector<int>>(n);
for (int i = 0; i < n - 1; ++i) {
--a[i]; --b[i];
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
type = vector<int>(n, 0);
}
int solve() {
static const int INF = (int)1e9;
vector<vector<int>> dp(n, vector<int>(2, INF));
function<void(int, int)> dfs = [&](int v, int p) {
for (int u : g[v]) {
if (u != p) dfs(u, v);
}
if (type[v] != 1) {
dp[v][0] = 0;
for (int u : g[v]) dp[v][0] += min(dp[u][0], dp[u][1] + 1);
}
if (type[v] != 2) {
dp[v][1] = 0;
for (int u : g[v]) dp[v][1] += min(dp[u][1], dp[u][0] + 1);
}
};
dfs(0, -1);
return min(dp[0][0], dp[0][1]);
}
int cat(int v) {
type[v] = 1;
return solve();
}
int dog(int v) {
type[v] = 2;
return solve();
}
int neighbor(int v) {
type[v] = 0;
return solve();
}
#ifdef LOCAL
int main() {
freopen("input.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |