Submission #1060704

# Submission time Handle Problem Language Result Execution time Memory
1060704 2024-08-15T20:56:27 Z MilosMilutinovic The Ties That Guide Us (CEOI23_incursion) C++17
30 / 100
305 ms 16148 KB
#include "incursion.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> mark(vector<pair<int, int>> e, int safe) {
  --safe;
  int n = (int) e.size() + 1;
  vector<vector<int>> g(n);
  for (int i = 0; i + 1 < n; i++) {
    --e[i].first; --e[i].second;
    g[e[i].first].push_back(e[i].second);
    g[e[i].second].push_back(e[i].first);
  }
  int root;
  {
    vector<int> sz(n);
    function<void(int, int)> Dfs = [&](int v, int pv) {
      sz[v] = 1;
      for (int u : g[v]) {
        if (u == pv) {
          continue;
        }
        Dfs(u, v);
        sz[v] += sz[u];
      }
    };
    Dfs(0, 0);
    vector<int> cen;
    function<int(int, int)> FindCentroid = [&](int v, int pv) {
      if (sz[v] * 2 == n) {
        cen.push_back(pv);
      }
      for (int u : g[v]) {
        if (u == pv || sz[u] * 2 < n) {
          continue;
        }
        return FindCentroid(u, v);
      }
      cen.push_back(v);
      return v;
    };
    root = FindCentroid(0, 0);
    if ((int) cen.size() == 2) {
      vector<int> que(1, safe);
      vector<bool> was(n);
      was[safe] = true;
      for (int b = 0; b < (int) que.size(); b++) {
        int i = que[b];
        if (i == cen[0] || i == cen[1]) {
          root = i;
          break;
        }
        for (int j : g[i]) {
          if (!was[j]) {
            que.push_back(j);
            was[j] = true;
          }
        }
      }
    }
  }
  vector<int> dfn(n);
  vector<int> dfo(n);
  int T = -1;
  function<void(int, int)> Dfs = [&](int v, int pv) {
    dfn[v] = ++T;
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      Dfs(u, v);
    }
    dfo[v] = T;
  };
  Dfs(root, root);
  vector<int> seq(n);
  for (int i = 0; i < n; i++) {
    if (dfn[i] <= dfn[safe] && dfo[safe] <= dfo[i]) {
      seq[i] = 1;
    } else {
      seq[i] = 0;
    }
  }
  return seq;
}

void locate(vector<pair<int, int>> e, int curr, int t) {
  --curr;
  int n = (int) e.size() + 1;
  vector<vector<int>> g(n);
  for (int i = 0; i + 1 < n; i++) {
    --e[i].first; --e[i].second;
    g[e[i].first].push_back(e[i].second);
    g[e[i].second].push_back(e[i].first);
  }
  vector<int> cen;
  {
    vector<int> sz(n);
    function<void(int, int)> Dfs = [&](int v, int pv) {
      sz[v] = 1;
      for (int u : g[v]) {
        if (u == pv) {
          continue;
        }
        Dfs(u, v);
        sz[v] += sz[u];
      }
    };
    Dfs(0, 0);
    function<void(int, int)> Find = [&](int v, int pv) {
      if (sz[v] * 2 == n) {
        cen.push_back(pv);
      }
      for (int u : g[v]) {
        if (u == pv || sz[u] * 2 < n) {
          continue;
        }
        Find(u, v);
        return;
      }
      cen.push_back(v);
    };
    Find(0, 0);
  }
  int root = cen[0];
  vector<int> x(n, -1);
  vector<int> pr(n);
  vector<int> sz(n);
  function<void(int, int)> Dfs = [&](int v, int pv) {
    pr[v] = pv;
    sz[v] = 1;
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      Dfs(u, v);
      sz[v] += sz[u];
      if (x[v] == -1 || sz[x[v]] < sz[u]) {
        x[v] = u;
      }
    }
  };
  Dfs(root, root);
  while (true) {
    if (curr == root && t == 0) {
      root = cen[1];
      Dfs(root, root);
      continue;
    }
    if (t == 0) {
      t = visit(pr[curr] + 1);
      curr = pr[curr];
      continue;
    }
    if (x[curr] == -1) {
      return;
    }
    int k = visit(x[curr] + 1);
    if (k == 1) {
      curr = x[curr];
      t = k;
      continue;
    }
    visit(curr + 1);
    bool found = false;
    for (int u : g[curr]) {
      if (u == pr[curr] || u == x[curr]) {
        continue;
      }
      int k = visit(u + 1);
      if (k == 1) {
        t = k;
        curr = u;
        found = true;
        break;
      }
      visit(curr + 1);
    }
    if (!found) {
      return;
    }
  }
}

Compilation message

interface.cpp: In function 'int main()':
interface.cpp:44:55: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     if(fread(T.data(), sizeof(int), 2 * N - 2, stdin) != 2 * N - 2) exit(0);
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
interface.cpp:50:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         int l = (numbers.size() == N ? N : 0);
      |                  ~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 764 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 225 ms 13340 KB Correct
2 Correct 190 ms 13796 KB Correct
3 Correct 114 ms 14764 KB Correct
4 Correct 118 ms 15576 KB Correct
5 Correct 213 ms 15020 KB Correct
6 Correct 81 ms 15612 KB Correct
7 Correct 77 ms 13544 KB Correct
8 Correct 237 ms 14064 KB Correct
9 Correct 230 ms 14908 KB Correct
10 Correct 154 ms 13896 KB Correct
11 Correct 99 ms 15840 KB Correct
12 Correct 305 ms 13820 KB Correct
13 Correct 84 ms 13128 KB Correct
14 Correct 91 ms 13828 KB Correct
15 Correct 205 ms 14788 KB Correct
16 Correct 242 ms 16148 KB Correct
17 Correct 128 ms 12860 KB Correct
18 Correct 98 ms 13548 KB Correct
19 Correct 154 ms 12860 KB Correct
20 Correct 87 ms 15160 KB Correct
21 Correct 89 ms 14076 KB Correct
22 Correct 200 ms 13952 KB Correct
23 Correct 212 ms 14180 KB Correct
24 Correct 101 ms 13768 KB Correct
25 Correct 94 ms 15004 KB Correct
26 Correct 92 ms 13292 KB Correct
27 Correct 90 ms 13628 KB Correct
28 Correct 92 ms 14140 KB Correct
29 Correct 224 ms 14444 KB Correct
30 Correct 218 ms 12780 KB Correct
31 Correct 91 ms 15444 KB Correct
32 Correct 248 ms 14248 KB Correct
33 Correct 226 ms 14764 KB Correct
34 Correct 91 ms 13444 KB Correct
35 Correct 79 ms 12864 KB Correct
36 Correct 201 ms 14348 KB Correct
37 Correct 213 ms 14392 KB Correct
38 Correct 257 ms 15484 KB Correct
39 Correct 166 ms 15720 KB Correct
40 Correct 191 ms 15024 KB Correct
41 Correct 94 ms 14656 KB Correct
42 Correct 83 ms 14396 KB Correct
43 Correct 205 ms 14548 KB Correct
44 Correct 227 ms 12988 KB Correct
45 Correct 92 ms 13488 KB Correct
46 Correct 87 ms 13796 KB Correct
47 Correct 107 ms 14804 KB Correct
48 Correct 94 ms 12604 KB Correct
49 Correct 87 ms 15084 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 7928 KB Correct
2 Correct 80 ms 8000 KB Correct
3 Correct 83 ms 7996 KB Correct
4 Correct 86 ms 11844 KB Correct
5 Correct 152 ms 11200 KB Correct
6 Correct 174 ms 11284 KB Correct
7 Correct 87 ms 7856 KB Correct
8 Correct 79 ms 8004 KB Correct
9 Correct 79 ms 7948 KB Correct
10 Incorrect 71 ms 8008 KB Not correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 764 KB Correct
2 Correct 225 ms 13340 KB Correct
3 Correct 190 ms 13796 KB Correct
4 Correct 114 ms 14764 KB Correct
5 Correct 118 ms 15576 KB Correct
6 Correct 213 ms 15020 KB Correct
7 Correct 81 ms 15612 KB Correct
8 Correct 77 ms 13544 KB Correct
9 Correct 237 ms 14064 KB Correct
10 Correct 230 ms 14908 KB Correct
11 Correct 154 ms 13896 KB Correct
12 Correct 99 ms 15840 KB Correct
13 Correct 305 ms 13820 KB Correct
14 Correct 84 ms 13128 KB Correct
15 Correct 91 ms 13828 KB Correct
16 Correct 205 ms 14788 KB Correct
17 Correct 242 ms 16148 KB Correct
18 Correct 128 ms 12860 KB Correct
19 Correct 98 ms 13548 KB Correct
20 Correct 154 ms 12860 KB Correct
21 Correct 87 ms 15160 KB Correct
22 Correct 89 ms 14076 KB Correct
23 Correct 200 ms 13952 KB Correct
24 Correct 212 ms 14180 KB Correct
25 Correct 101 ms 13768 KB Correct
26 Correct 94 ms 15004 KB Correct
27 Correct 92 ms 13292 KB Correct
28 Correct 90 ms 13628 KB Correct
29 Correct 92 ms 14140 KB Correct
30 Correct 224 ms 14444 KB Correct
31 Correct 218 ms 12780 KB Correct
32 Correct 91 ms 15444 KB Correct
33 Correct 248 ms 14248 KB Correct
34 Correct 226 ms 14764 KB Correct
35 Correct 91 ms 13444 KB Correct
36 Correct 79 ms 12864 KB Correct
37 Correct 201 ms 14348 KB Correct
38 Correct 213 ms 14392 KB Correct
39 Correct 257 ms 15484 KB Correct
40 Correct 166 ms 15720 KB Correct
41 Correct 191 ms 15024 KB Correct
42 Correct 94 ms 14656 KB Correct
43 Correct 83 ms 14396 KB Correct
44 Correct 205 ms 14548 KB Correct
45 Correct 227 ms 12988 KB Correct
46 Correct 92 ms 13488 KB Correct
47 Correct 87 ms 13796 KB Correct
48 Correct 107 ms 14804 KB Correct
49 Correct 94 ms 12604 KB Correct
50 Correct 87 ms 15084 KB Correct
51 Correct 78 ms 7928 KB Correct
52 Correct 80 ms 8000 KB Correct
53 Correct 83 ms 7996 KB Correct
54 Correct 86 ms 11844 KB Correct
55 Correct 152 ms 11200 KB Correct
56 Correct 174 ms 11284 KB Correct
57 Correct 87 ms 7856 KB Correct
58 Correct 79 ms 8004 KB Correct
59 Correct 79 ms 7948 KB Correct
60 Incorrect 71 ms 8008 KB Not correct
61 Halted 0 ms 0 KB -