Submission #1004652

# Submission time Handle Problem Language Result Execution time Memory
1004652 2024-06-21T11:28:05 Z MilosMilutinovic Beech Tree (IOI23_beechtree) C++17
0 / 100
2000 ms 43852 KB
#include "beechtree.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> beechtree(int n, int m, vector<int> p, vector<int> c) {
  vector<vector<int>> ch(n);
  for (int i = 1; i < n; i++) {
    ch[p[i]].push_back(i);
  }
  vector<vector<int>> my(n);
  for (int i = 0; i < n; i++) {
    for (int j : ch[i]) {
      my[i].push_back(c[j]);
    }
  }
  vector<bool> diff(n);
  for (int i = 0; i < n; i++) {
    set<int> st(my[i].begin(), my[i].end());
    diff[i] = (st.size() == my[i].size());
  }
  vector<int> tin(n);
  vector<int> tout(n);
  int T = 0;
  function<void(int)> Dfs = [&](int v) {
    tin[v] = ++T;
    for (int u : ch[v]) {
      Dfs(u);
    }
    tout[v] = T;
  };
  Dfs(0);
  auto IsAnc = [&](int x, int y) {
    return tin[x] <= tin[y] && tout[y] <= tout[x];
  };
  auto IsSubset = [&](vector<int> a, vector<int> b) {
    set<int> st(a.begin(), a.end());
    for (int i : b) {
      if (st.find(i) == st.end()) {
        return false;
      }
    }
    return true;
  }; 
  auto NoIntersect = [&](vector<int> a, vector<int> b) {
    set<int> st;
    for (int i : a) {
      st.insert(i);
    }
    for (int i : b) {
      st.insert(i);
    }
    return st.size() == a.size() + b.size();
  };
  vector<int> res(n);
  for (int v = 0; v < n; v++) {
    bool ok = true;
    vector<int> ver;
    for (int i = 0; i < n; i++) {
      if (IsAnc(v, i)) {
        ver.push_back(i);
      }
    }
    for (int i : ver) {
      ok &= diff[i];
    }
    for (int i : ver) {
      if (i == v) {
        continue;
      }
      ok &= IsSubset(my[p[i]], my[i]);
    }
    for (int i : ver) {
      for (int j : ver) {
        if (IsAnc(i, j) || IsAnc(j, i)) {
          continue;
        }
        ok &= NoIntersect(my[i], my[j]);
      }
    }
    res[v] = ok;
  }
  return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 2 ms 344 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 432 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Incorrect 1 ms 344 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Execution timed out 2035 ms 43852 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 436 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Execution timed out 2035 ms 43852 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 2 ms 344 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 432 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Incorrect 1 ms 344 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 2 ms 344 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 432 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Incorrect 1 ms 344 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 2 ms 344 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -