Submission #939953

# Submission time Handle Problem Language Result Execution time Memory
939953 2024-03-07T02:21:35 Z sleepntsheep Cats or Dogs (JOI18_catdog) C++17
38 / 100
18 ms 4188 KB
#include "catdog.h"
#include<stdio.h>
#include<algorithm>


#define N 2000

int shin[N],dp[N][2], e[N][2],ne,h[N];

void link(int u,int v)
{
    e[++ne][0]=v,e[ne][1]=h[u],h[u]=ne;
}

void dfs(int u,int p)
{
    dp[u][0]=dp[u][1]=0;
    for(int v,j=h[u];j;j=e[j][1])if((v=e[j][0])-p)
    {
        dfs(v,u);
        for(int k=0;k<2;++k)
            dp[u][k]+=std::min(dp[v][k],dp[v][k^1]+1);
    }
    if(shin[u])
    {
        dp[u][(shin[u]-1)^1]=1e9;
    }
}

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

int cat(int u) {
    shin[u]=1;
    dfs(1,1);
    return std::min(dp[1][0],dp[1][1]);
}

int dog(int u) {
    shin[u]=2;
    dfs(1,1);
    return std::min(dp[1][0],dp[1][1]);
}

int neighbor(int u) {
    shin[u]=0;
    dfs(1,1);
    return std::min(dp[1][0],dp[1][1]);
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 5 ms 348 KB Output is correct
18 Correct 6 ms 348 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 7 ms 500 KB Output is correct
24 Correct 5 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 10 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 5 ms 348 KB Output is correct
18 Correct 6 ms 348 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 7 ms 500 KB Output is correct
24 Correct 5 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 10 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Runtime error 18 ms 4188 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -