Submission #374820

# Submission time Handle Problem Language Result Execution time Memory
374820 2021-03-08T09:16:17 Z valerikk Cats or Dogs (JOI18_catdog) C++17
38 / 100
3000 ms 8540 KB
/*
    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
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 64 ms 364 KB Output is correct
18 Correct 80 ms 492 KB Output is correct
19 Correct 42 ms 480 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 12 ms 492 KB Output is correct
22 Correct 15 ms 364 KB Output is correct
23 Correct 90 ms 492 KB Output is correct
24 Correct 79 ms 484 KB Output is correct
25 Correct 36 ms 436 KB Output is correct
26 Correct 15 ms 364 KB Output is correct
27 Correct 9 ms 364 KB Output is correct
28 Correct 16 ms 492 KB Output is correct
29 Correct 82 ms 492 KB Output is correct
30 Correct 10 ms 364 KB Output is correct
31 Correct 6 ms 364 KB Output is correct
32 Correct 17 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 64 ms 364 KB Output is correct
18 Correct 80 ms 492 KB Output is correct
19 Correct 42 ms 480 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 12 ms 492 KB Output is correct
22 Correct 15 ms 364 KB Output is correct
23 Correct 90 ms 492 KB Output is correct
24 Correct 79 ms 484 KB Output is correct
25 Correct 36 ms 436 KB Output is correct
26 Correct 15 ms 364 KB Output is correct
27 Correct 9 ms 364 KB Output is correct
28 Correct 16 ms 492 KB Output is correct
29 Correct 82 ms 492 KB Output is correct
30 Correct 10 ms 364 KB Output is correct
31 Correct 6 ms 364 KB Output is correct
32 Correct 17 ms 492 KB Output is correct
33 Execution timed out 3063 ms 8540 KB Time limit exceeded
34 Halted 0 ms 0 KB -