이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
    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) {
        vector<int> gg;
        for (int u : g[v]) {
            if (u != p) {
                dfs(u, v);
                gg.push_back(u);
            }
        }
        if (type[v] != 1) {
            dp[v][0] = 0;
            for (int u : gg) dp[v][0] += min(dp[u][0], dp[u][1] + 1);
        }
        if (type[v] != 2) {
            dp[v][1] = 0;
            for (int u : gg) 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) {
    --v;
    type[v] = 1;
    return solve();
}
int dog(int v) {
    --v;
    type[v] = 2;
    return solve();
}
int neighbor(int v) {
    --v;
    type[v] = 0;
    return solve();
}
#ifndef EVAL
int main() {
    freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    return 0;
}
#endif
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |