Submission #722086

# Submission time Handle Problem Language Result Execution time Memory
722086 2023-04-11T11:52:10 Z viwlesxq Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
9 ms 512 KB
#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;
typedef string str;

int query(vector <int> islands);

int findEgg(int n, vector <pair <int, int>> edges) {
  vector <int> g[n + 1];
  int par[n + 1], sz[n + 1];
  vector <bool> used(n + 1, false);
  for (auto [a, b] : edges) {
    g[a].push_back(b);
    g[b].push_back(a);
  }
  function <void(int, int)> prepare = [&](int v, int p) {
    par[v] = p;
    sz[v] = 1;
    for (int to : g[v]) {
      if (to == p) {
        continue;
      }
      prepare(to, v);
      sz[v] += sz[to];
    }
  };
  prepare(1, -1);
  function <int(int, int)> get_centroid = [&](int v, int p) {
    for (int to : g[v]) {
      if (to == p || used[to]) {
        continue;
      }
      if (sz[to] * 2 > n) {
        return get_centroid(to, v);
      }
    }
    return v;
  };
  vector <int> subtree;
  function <void(int, int)> get_subtree = [&](int v, int p) {
    subtree.push_back(v);
    for (int to : g[v]) {
      if (to == p || used[to]) {
        continue;
      }
      get_subtree(to, v);
    }
  };
  int root = 1;
  do {
    subtree.clear();
    int centroid = get_centroid(root, par[root]);
    get_subtree(centroid, par[centroid]);
    if (query(subtree)) {
      root = centroid;
      n = sz[root];
    } else {
      used[centroid] = true;
      n -= sz[centroid];
      int cur = centroid;
      while (par[cur] != -1) {
        sz[par[cur]] -= sz[centroid];
        cur = par[cur];
      }
    }
  } while (n > 2);
  subtree.clear();
  int centroid = get_centroid(root, par[root]);
  get_subtree(centroid, par[centroid]);
  if (query({subtree.back()})) {
    return subtree.back();
  } else {
    return root;
  }
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 336 KB Number of queries: 9
2 Runtime error 3 ms 460 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 9 ms 336 KB Number of queries: 10
2 Runtime error 1 ms 472 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -