Submission #1083458

# Submission time Handle Problem Language Result Execution time Memory
1083458 2024-09-03T08:45:08 Z Boycl07 Cats or Dogs (JOI18_catdog) C++17
0 / 100
2 ms 2652 KB
#include "catdog.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "note"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }

const int MaxN = 1e5 + 1;

int n;
int pet[MaxN];
vector<int> g[MaxN];



void initialize(int n_, vector<int> A, vector<int> B)
{
    n = n_;
    rep(i, n) pet[i] = 0;
    rep(i, n - 1)
    {
        int u = A[i - 1], v = B[i - 1];
        g[u].pb(v);
        g[v].pb(u);
    }
}

int dfs(int u, int p, int cur_pet)
{
    int res = 0;
    if(u != p)
        if(pet[u] && pet[u] != cur_pet) ++res, cur_pet = pet[u];
    for(int v : g[u]) if(v != p)
        res += dfs(v, u, cur_pet);
    return res;
}

int get()
{
    int res = n;
    if(pet[1] >= 0) minimize(res, dfs(1, 1, 1));
    if(pet[1] <= 0) minimize(res, dfs(1, 1, -1));
    return res;
}

int cat(int x)
{
    pet[x] = 1;
    return get();
}

int dog(int x)
{
    pet[x] = -1;
    return get();
}

int neighbor(int x)
{
    pet[x] = 0;
    return get();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Incorrect 2 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Incorrect 2 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Incorrect 2 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -