Submission #95893

# Submission time Handle Problem Language Result Execution time Memory
95893 2019-02-03T12:03:17 Z onjo0127 Cats or Dogs (JOI18_catdog) C++11
38 / 100
3000 ms 9448 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);
    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] = (A[x] == 2 ? 1e9 : s1);
    D[1][x] = (A[x] == 1 ? 1e9 : s2);
}

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 5 ms 4984 KB Output is correct
2 Correct 5 ms 4984 KB Output is correct
3 Correct 5 ms 4984 KB Output is correct
4 Correct 5 ms 4984 KB Output is correct
5 Correct 5 ms 4984 KB Output is correct
6 Correct 5 ms 5084 KB Output is correct
7 Correct 10 ms 4984 KB Output is correct
8 Correct 5 ms 5112 KB Output is correct
9 Correct 5 ms 4984 KB Output is correct
10 Correct 5 ms 4984 KB Output is correct
11 Correct 5 ms 5112 KB Output is correct
12 Correct 6 ms 4984 KB Output is correct
13 Correct 6 ms 4984 KB Output is correct
14 Correct 5 ms 4984 KB Output is correct
15 Correct 5 ms 4984 KB Output is correct
16 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 4984 KB Output is correct
3 Correct 5 ms 4984 KB Output is correct
4 Correct 5 ms 4984 KB Output is correct
5 Correct 5 ms 4984 KB Output is correct
6 Correct 5 ms 5084 KB Output is correct
7 Correct 10 ms 4984 KB Output is correct
8 Correct 5 ms 5112 KB Output is correct
9 Correct 5 ms 4984 KB Output is correct
10 Correct 5 ms 4984 KB Output is correct
11 Correct 5 ms 5112 KB Output is correct
12 Correct 6 ms 4984 KB Output is correct
13 Correct 6 ms 4984 KB Output is correct
14 Correct 5 ms 4984 KB Output is correct
15 Correct 5 ms 4984 KB Output is correct
16 Correct 6 ms 4984 KB Output is correct
17 Correct 10 ms 5112 KB Output is correct
18 Correct 12 ms 5112 KB Output is correct
19 Correct 9 ms 5112 KB Output is correct
20 Correct 6 ms 5112 KB Output is correct
21 Correct 7 ms 4984 KB Output is correct
22 Correct 7 ms 4984 KB Output is correct
23 Correct 13 ms 5112 KB Output is correct
24 Correct 12 ms 5112 KB Output is correct
25 Correct 8 ms 4984 KB Output is correct
26 Correct 6 ms 4984 KB Output is correct
27 Correct 6 ms 5112 KB Output is correct
28 Correct 7 ms 5112 KB Output is correct
29 Correct 15 ms 5112 KB Output is correct
30 Correct 6 ms 4984 KB Output is correct
31 Correct 5 ms 5112 KB Output is correct
32 Correct 6 ms 4988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 4984 KB Output is correct
3 Correct 5 ms 4984 KB Output is correct
4 Correct 5 ms 4984 KB Output is correct
5 Correct 5 ms 4984 KB Output is correct
6 Correct 5 ms 5084 KB Output is correct
7 Correct 10 ms 4984 KB Output is correct
8 Correct 5 ms 5112 KB Output is correct
9 Correct 5 ms 4984 KB Output is correct
10 Correct 5 ms 4984 KB Output is correct
11 Correct 5 ms 5112 KB Output is correct
12 Correct 6 ms 4984 KB Output is correct
13 Correct 6 ms 4984 KB Output is correct
14 Correct 5 ms 4984 KB Output is correct
15 Correct 5 ms 4984 KB Output is correct
16 Correct 6 ms 4984 KB Output is correct
17 Correct 10 ms 5112 KB Output is correct
18 Correct 12 ms 5112 KB Output is correct
19 Correct 9 ms 5112 KB Output is correct
20 Correct 6 ms 5112 KB Output is correct
21 Correct 7 ms 4984 KB Output is correct
22 Correct 7 ms 4984 KB Output is correct
23 Correct 13 ms 5112 KB Output is correct
24 Correct 12 ms 5112 KB Output is correct
25 Correct 8 ms 4984 KB Output is correct
26 Correct 6 ms 4984 KB Output is correct
27 Correct 6 ms 5112 KB Output is correct
28 Correct 7 ms 5112 KB Output is correct
29 Correct 15 ms 5112 KB Output is correct
30 Correct 6 ms 4984 KB Output is correct
31 Correct 5 ms 5112 KB Output is correct
32 Correct 6 ms 4988 KB Output is correct
33 Execution timed out 3026 ms 9448 KB Time limit exceeded
34 Halted 0 ms 0 KB -