Submission #213563

# Submission time Handle Problem Language Result Execution time Memory
213563 2020-03-26T06:46:19 Z erd1 Cats or Dogs (JOI18_catdog) C++14
0 / 100
5 ms 384 KB
#include "catdog.h"
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
typedef pair<int, int> pii;
vector<int> o;
vector<vector<int>> G;
void initialize(int N, std::vector<int> A, std::vector<int> B) {
  G.resize(N+1);
  o.resize(N+1);
  for(int i = 0; i < N-1; i++){
    G[A[i]].pb(B[i]);
    G[B[i]].pb(A[i]);
  }
}

pii dfs(int i, int par){
//cout << i << " " << par << endl;
    pii ans = {o[i]&1, o[i]>>1};
    for(auto x: G[i]){
        if(x == par)continue;
        auto a = dfs(x, i);
        ans.ss += min(a.ss, a.ff+1);
        ans.ff += min(a.ff, a.ss+1);
    }
    return ans;
}

int min(pii x){
    return min(x.ff, x.ss);
}

int cat(int v) {
  o[v] = 1;
  return min(dfs(1, 1));
}

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

int neighbor(int v) {
  o[v] = 0;
  return min(dfs(1, 1));
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 128 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 128 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 128 KB Output isn't correct
3 Halted 0 ms 0 KB -