Submission #95892

# Submission time Handle Problem Language Result Execution time Memory
95892 2019-02-03T12:02:05 Z onjo0127 Cats or Dogs (JOI18_catdog) C++11
38 / 100
3000 ms 10728 KB
#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;

int A[100009], D[2][100009];
vector<int> adj[100009], tree[100009];

void dfs(int x, int p) {
    for(auto& it: adj[x]) {
        if(it != p) {
            tree[x].push_back(it);
            dfs(it, x);
        }
    }
}

void initialize(int N, vector<int> A, vector<int> B) {
    for(int i=0; i<N-1; i++) {
        int u = A[i], v = B[i];
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1, 1);
}

void go(int x) {
    for(auto& it: tree[x]) go(it);
    if(A[x] == 0) {
        int s1 = 0, s2 = 0;
        for(auto& it: tree[x]) {
            s1 += min(D[0][it], D[1][it] + 1);
            s2 += min(D[1][it], D[0][it] + 1);
        }
        D[0][x] = s1;
        D[1][x] = s2;
    }
    if(A[x] == 1) {
        int s = 0;
        for(auto& it: tree[x]) s += min(D[0][it], D[1][it] + 1);
        D[0][x] = s;
        D[1][x] = 1e9;
    }
    if(A[x] == 2) {
        int s = 0;
        for(auto& it: tree[x]) s += min(D[0][it] + 1, D[1][it]);
        D[0][x] = 1e9;
        D[1][x] = s;
    }
}

int DP() {
    go(1);
    return min(D[0][1], D[1][1]);
}

int cat(int v) {
    A[v] = 1;
    return DP();
}

int dog(int v) {
    A[v] = 2;
    return DP();
}

int neighbor(int v) {
    A[v] = 0;
    return DP();
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 4988 KB Output is correct
6 Correct 5 ms 4984 KB Output is correct
7 Correct 6 ms 4984 KB Output is correct
8 Correct 5 ms 5112 KB Output is correct
9 Correct 6 ms 5112 KB Output is correct
10 Correct 6 ms 4984 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 6 ms 4984 KB Output is correct
13 Correct 5 ms 4984 KB Output is correct
14 Correct 5 ms 5112 KB Output is correct
15 Correct 5 ms 5112 KB Output is correct
16 Correct 5 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 4988 KB Output is correct
6 Correct 5 ms 4984 KB Output is correct
7 Correct 6 ms 4984 KB Output is correct
8 Correct 5 ms 5112 KB Output is correct
9 Correct 6 ms 5112 KB Output is correct
10 Correct 6 ms 4984 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 6 ms 4984 KB Output is correct
13 Correct 5 ms 4984 KB Output is correct
14 Correct 5 ms 5112 KB Output is correct
15 Correct 5 ms 5112 KB Output is correct
16 Correct 5 ms 4984 KB Output is correct
17 Correct 14 ms 5112 KB Output is correct
18 Correct 11 ms 5112 KB Output is correct
19 Correct 8 ms 5112 KB Output is correct
20 Correct 5 ms 4984 KB Output is correct
21 Correct 6 ms 5112 KB Output is correct
22 Correct 7 ms 5112 KB Output is correct
23 Correct 14 ms 5112 KB Output is correct
24 Correct 12 ms 5116 KB Output is correct
25 Correct 8 ms 5112 KB Output is correct
26 Correct 7 ms 5112 KB Output is correct
27 Correct 7 ms 4984 KB Output is correct
28 Correct 8 ms 5112 KB Output is correct
29 Correct 17 ms 5240 KB Output is correct
30 Correct 6 ms 4984 KB Output is correct
31 Correct 6 ms 5112 KB Output is correct
32 Correct 7 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 4988 KB Output is correct
6 Correct 5 ms 4984 KB Output is correct
7 Correct 6 ms 4984 KB Output is correct
8 Correct 5 ms 5112 KB Output is correct
9 Correct 6 ms 5112 KB Output is correct
10 Correct 6 ms 4984 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 6 ms 4984 KB Output is correct
13 Correct 5 ms 4984 KB Output is correct
14 Correct 5 ms 5112 KB Output is correct
15 Correct 5 ms 5112 KB Output is correct
16 Correct 5 ms 4984 KB Output is correct
17 Correct 14 ms 5112 KB Output is correct
18 Correct 11 ms 5112 KB Output is correct
19 Correct 8 ms 5112 KB Output is correct
20 Correct 5 ms 4984 KB Output is correct
21 Correct 6 ms 5112 KB Output is correct
22 Correct 7 ms 5112 KB Output is correct
23 Correct 14 ms 5112 KB Output is correct
24 Correct 12 ms 5116 KB Output is correct
25 Correct 8 ms 5112 KB Output is correct
26 Correct 7 ms 5112 KB Output is correct
27 Correct 7 ms 4984 KB Output is correct
28 Correct 8 ms 5112 KB Output is correct
29 Correct 17 ms 5240 KB Output is correct
30 Correct 6 ms 4984 KB Output is correct
31 Correct 6 ms 5112 KB Output is correct
32 Correct 7 ms 5112 KB Output is correct
33 Execution timed out 3033 ms 10728 KB Time limit exceeded
34 Halted 0 ms 0 KB -