Submission #674268

# Submission time Handle Problem Language Result Execution time Memory
674268 2022-12-23T15:25:29 Z tibinyte Cats or Dogs (JOI18_catdog) C++14
38 / 100
3000 ms 8484 KB
#include <bits/stdc++.h>
#include "catdog.h"
using namespace std;
const int inf = 1e5;
vector<int> a;
vector<vector<int>> g;
vector<vector<int>> dp;
void initialize(int N, vector<int> A, vector<int> B)
{
  g = vector<vector<int>>(N + 1);
  dp = vector<vector<int>>(N + 1, vector<int>(2));
  a = vector<int>(N + 1, 2);
  for (int i = 0; i <= N - 2; ++i)
  {
    g[A[i]].push_back(B[i]);
    g[B[i]].push_back(A[i]);
  }
}
void dfs(int node, int parent)
{
  for (int i = 0; i < 2; ++i)
  {
    dp[node][i] = 0;
  }
  for (auto i : g[node])
  {
    if (i != parent)
    {
      dfs(i, node);
      for (int j = 0; j < 2; ++j)
      {
        dp[node][j] += min(dp[i][j], dp[i][j ^ 1] + 1);
      }
    }
  }
  if (a[node] != 2)
  {
    dp[node][a[node]] = inf;
  }
}
int cat(int v)
{
  a[v] = 0;
  dfs(1, 0);
  return min(dp[1][0], dp[1][1]);
}

int dog(int v)
{
  a[v] = 1;
  dfs(1, 0);
  return min(dp[1][0], dp[1][1]);
}

int neighbor(int v)
{
  a[v] = 2;
  dfs(1, 0);
  return min(dp[1][0], dp[1][1]);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 0 ms 300 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 0 ms 300 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 12 ms 340 KB Output is correct
18 Correct 17 ms 340 KB Output is correct
19 Correct 9 ms 412 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 3 ms 300 KB Output is correct
23 Correct 20 ms 424 KB Output is correct
24 Correct 16 ms 396 KB Output is correct
25 Correct 7 ms 304 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 23 ms 440 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 0 ms 300 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 12 ms 340 KB Output is correct
18 Correct 17 ms 340 KB Output is correct
19 Correct 9 ms 412 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 3 ms 300 KB Output is correct
23 Correct 20 ms 424 KB Output is correct
24 Correct 16 ms 396 KB Output is correct
25 Correct 7 ms 304 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 23 ms 440 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Execution timed out 3064 ms 8484 KB Time limit exceeded
34 Halted 0 ms 0 KB -