Submission #213566

# Submission time Handle Problem Language Result Execution time Memory
213566 2020-03-26T06:56:30 Z erd1 Cats or Dogs (JOI18_catdog) C++14
38 / 100
3000 ms 5880 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 = {0, 0};
    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);
    }
    if(o[i]&1)ans.ff = INT_MAX-1;
    if(o[i]>>1)ans.ss = INT_MAX-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 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 13 ms 384 KB Output is correct
19 Correct 9 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 16 ms 384 KB Output is correct
24 Correct 13 ms 384 KB Output is correct
25 Correct 8 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Correct 16 ms 512 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 13 ms 384 KB Output is correct
19 Correct 9 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 16 ms 384 KB Output is correct
24 Correct 13 ms 384 KB Output is correct
25 Correct 8 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Correct 16 ms 512 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 6 ms 384 KB Output is correct
33 Execution timed out 3099 ms 5880 KB Time limit exceeded
34 Halted 0 ms 0 KB -