Submission #669159

# Submission time Handle Problem Language Result Execution time Memory
669159 2022-12-05T20:54:28 Z tibinyte Cats or Dogs (JOI18_catdog) C++14
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
#include "catdog.h"
using namespace std;
const int inf = 1e9;
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 = 1; i <= N; ++i)
    {
        g[A[i]].emplace_back(B[i]);
        g[B[i]].emplace_back(A[i]);
    }
}
void dfs(int node, int parent)
{
    for (int i = 0; i < 2; ++i)
    {
        dp[node][i] = inf;
    }
    bool leaf = true;
    for (auto i : g[node])
    {
        if (i != parent)
        {
            dfs(i, node);
            for (int j = 0; j < 2; ++j)
            {
                dp[node][j] = min({dp[node][j], dp[i][j], dp[i][j ^ 1] + 1});
            }
            leaf = false;
        }
    }
    if (leaf)
    {
        if (a[node] == 2)
        {
            for (int i = 0; i < 1; ++i)
            {
                dp[node][i] = 0;
            }
        }
        else
        {
            dp[node][a[node]] = 0;
        }
    }
    if (a[node] != 2)
    {
        dp[node][a[node] ^ 1] = 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 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -