Submission #388124

# Submission time Handle Problem Language Result Execution time Memory
388124 2021-04-10T07:42:08 Z mohamedsobhi777 Cats or Dogs (JOI18_catdog) C++14
38 / 100
34 ms 4300 KB
#include <bits/stdc++.h>
#include "catdog.h"

using namespace std;

int x;
const int MX = 1000 + 7;
int val[MX];
vector<int> adj[MX];
int dp[MX][2];

void initialize(int N, std::vector<int> A, std::vector<int> B)
{
       x = N;
       for (int i = 0; i + 1 < N; ++i)
       {
              adj[A[i]].push_back(B[i]);
              adj[B[i]].push_back(A[i]);
       }
       fill(val + 1, val + N + 1, 2);
}

void dfs(int x, int p)
{
       if (val[x] != 2)
              dp[x][!val[x]] = MX;
       for (auto u : adj[x])
       {
              if (u == p)
                     continue;
              dfs(u, x);
              dp[x][0] += min(dp[u][0], dp[u][1] + 1);
              dp[x][1] += min(dp[u][1], dp[u][0] + 1);
       }
}

int solve()
{
       memset(dp, 0, sizeof dp);
       dfs(1, 1);
       return min(dp[1][0], dp[1][1]);
}

int cat(int v)
{
       val[v] = 0;
       return solve();
}

int dog(int v)
{
       val[v] = 1;
       return solve();
}

int neighbor(int v)
{
       val[v] = 2;
       return solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 10 ms 368 KB Output is correct
18 Correct 12 ms 332 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 15 ms 396 KB Output is correct
24 Correct 13 ms 332 KB Output is correct
25 Correct 6 ms 360 KB Output is correct
26 Correct 3 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 17 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 10 ms 368 KB Output is correct
18 Correct 12 ms 332 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 15 ms 396 KB Output is correct
24 Correct 13 ms 332 KB Output is correct
25 Correct 6 ms 360 KB Output is correct
26 Correct 3 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 17 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Runtime error 34 ms 4300 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -