Submission #884000

# Submission time Handle Problem Language Result Execution time Memory
884000 2023-12-06T14:05:22 Z vjudge1 Cats or Dogs (JOI18_catdog) C++17
0 / 100
1 ms 5212 KB
#include <vector>
#include <bits/stdc++.h>
#include <iostream>
#include "catdog.h"

using namespace std;
using ll = long long;
const int NMAX = 1e5;
const ll INF = 1e4;

int x , n;

vector<int> adj[NMAX+1];
int stat[NMAX+1];
ll dp[3][NMAX+1];

void dfs (int nod = 1, int par = 0)
{
    dp[0][nod] = 0;
    dp[1][nod] = 0;
    dp[2][nod] = 0;
    for (int &to : adj[nod])
    {
        if (to != par)
        {
            dfs(to, nod);
            if (stat[nod] != 2)
                dp[stat[nod]][nod] += min(min(dp[2][to] , dp[stat[nod]][to]) , dp[stat[nod]^1][to]+1);
            else {
                dp[2][nod] += min({dp[0][to] + 1 , dp[1][to] + 1, dp[2][to]});
                dp[1][nod] += dp[1][to];
                dp[0][nod] += dp[0][to];

            }
        }
    }
    if (stat[nod] != 2)
    {
        dp[2][nod] = dp[stat[nod]^1][nod] = INF;
    }
    else dp[0][nod] = dp[1][nod] = INF;
}

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

int cat(int v) {
  stat[v] = 1;
  dfs();
  return min({dp[0][1], dp[1][1], dp[2][1]});
}

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

int neighbor(int v) {
  stat[v] = 2;
  dfs();
  return min({dp[0][1], dp[1][1], dp[2][1]});
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -