Submission #363249

# Submission time Handle Problem Language Result Execution time Memory
363249 2021-02-05T11:38:23 Z teewar Cats or Dogs (JOI18_catdog) C++14
38 / 100
33 ms 3436 KB
#include "catdog.h"
#include <algorithm>

using namespace std;

const int MAX = 1000;
const int INF = 1e9;

int d[MAX + 10][3];
vector<int> g[MAX + 10];
int best[MAX + 10];
int st[MAX + 10];



void dfs(int v, int p = -1) {
    d[v][st[v]] = 0;
    if(st[v] == 0) {
        d[v][1] = d[v][2] = 0;
    }
    for(auto to: g[v]) {
        if(p == to) {
            continue;
        }
        dfs(to, v);
        d[v][st[v]] += min({d[to][0], d[to][1] + 1, d[to][2] + 1, d[to][st[v]]});
        if(st[v] == 0) {
            d[v][1] += min({d[to][0], d[to][1] + 1, d[to][2] + 1, d[to][1]});
            d[v][2] += min({d[to][0], d[to][1] + 1, d[to][2] + 1, d[to][2]});
        }
    }
}


int ans() {
    for(int i = 0; i < MAX; ++i) {
        for(int j = 0; j < 3; ++j) {
            d[i][j] = INF;
        }
    }
    dfs(0);
    return min({d[0][0], d[0][1], d[0][2]});
}

void initialize(int n, vector<int> a, vector<int> b) {
    for(int i = 0; i < n - 1; ++i) {
        g[a[i] - 1].push_back(b[i] - 1);
      	g[b[i] - 1].push_back(a[i] - 1);
    }
}

int cat(int v){
    --v;
    st[v] = 1;
    return ans();
}


int dog(int v) {
    --v;
    st[v] = 2;
    return ans();
}


int neighbor(int v) {
    --v;
    st[v] = 0;
    return ans();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 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 384 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 512 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 364 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 384 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 22 ms 364 KB Output is correct
18 Correct 28 ms 364 KB Output is correct
19 Correct 14 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 6 ms 364 KB Output is correct
22 Correct 7 ms 364 KB Output is correct
23 Correct 32 ms 364 KB Output is correct
24 Correct 27 ms 492 KB Output is correct
25 Correct 12 ms 364 KB Output is correct
26 Correct 6 ms 364 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 6 ms 620 KB Output is correct
29 Correct 29 ms 620 KB Output is correct
30 Correct 6 ms 364 KB Output is correct
31 Correct 3 ms 364 KB Output is correct
32 Correct 10 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 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 384 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 22 ms 364 KB Output is correct
18 Correct 28 ms 364 KB Output is correct
19 Correct 14 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 6 ms 364 KB Output is correct
22 Correct 7 ms 364 KB Output is correct
23 Correct 32 ms 364 KB Output is correct
24 Correct 27 ms 492 KB Output is correct
25 Correct 12 ms 364 KB Output is correct
26 Correct 6 ms 364 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 6 ms 620 KB Output is correct
29 Correct 29 ms 620 KB Output is correct
30 Correct 6 ms 364 KB Output is correct
31 Correct 3 ms 364 KB Output is correct
32 Correct 10 ms 364 KB Output is correct
33 Runtime error 33 ms 3436 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -