Submission #1060723

# Submission time Handle Problem Language Result Execution time Memory
1060723 2024-08-15T21:18:13 Z MilosMilutinovic The Ties That Guide Us (CEOI23_incursion) C++17
30 / 100
282 ms 16476 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;
          }
        }
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if ((int) g[i].size() == 2) {
      cnt += 1;
    }
  }
  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];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if ((int) g[i].size() == 2) {
      cnt += 1;
    }
  }
  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];
      x = vector<int>(n, -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 196 ms 13232 KB Correct
2 Correct 230 ms 13796 KB Correct
3 Correct 117 ms 14720 KB Correct
4 Correct 110 ms 15348 KB Correct
5 Correct 190 ms 15240 KB Correct
6 Correct 88 ms 15688 KB Correct
7 Correct 84 ms 13752 KB Correct
8 Correct 222 ms 14072 KB Correct
9 Correct 219 ms 14728 KB Correct
10 Correct 157 ms 13556 KB Correct
11 Correct 115 ms 15904 KB Correct
12 Correct 282 ms 13980 KB Correct
13 Correct 87 ms 13120 KB Correct
14 Correct 88 ms 13716 KB Correct
15 Correct 215 ms 14764 KB Correct
16 Correct 227 ms 16476 KB Correct
17 Correct 126 ms 12864 KB Correct
18 Correct 95 ms 13668 KB Correct
19 Correct 143 ms 12880 KB Correct
20 Correct 84 ms 15340 KB Correct
21 Correct 84 ms 13884 KB Correct
22 Correct 219 ms 13880 KB Correct
23 Correct 208 ms 14324 KB Correct
24 Correct 116 ms 13552 KB Correct
25 Correct 97 ms 14644 KB Correct
26 Correct 93 ms 13220 KB Correct
27 Correct 80 ms 13900 KB Correct
28 Correct 95 ms 14336 KB Correct
29 Correct 216 ms 14412 KB Correct
30 Correct 217 ms 13072 KB Correct
31 Correct 87 ms 15600 KB Correct
32 Correct 229 ms 14372 KB Correct
33 Correct 222 ms 14812 KB Correct
34 Correct 91 ms 13444 KB Correct
35 Correct 91 ms 12796 KB Correct
36 Correct 212 ms 14356 KB Correct
37 Correct 221 ms 14396 KB Correct
38 Correct 244 ms 15232 KB Correct
39 Correct 162 ms 15568 KB Correct
40 Correct 208 ms 15344 KB Correct
41 Correct 86 ms 14828 KB Correct
42 Correct 90 ms 14652 KB Correct
43 Correct 209 ms 14348 KB Correct
44 Correct 228 ms 12644 KB Correct
45 Correct 99 ms 13480 KB Correct
46 Correct 88 ms 13792 KB Correct
47 Correct 115 ms 14572 KB Correct
48 Correct 84 ms 12860 KB Correct
49 Correct 86 ms 15108 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 8184 KB Correct
2 Correct 78 ms 8000 KB Correct
3 Correct 84 ms 8144 KB Correct
4 Correct 97 ms 12096 KB Correct
5 Correct 126 ms 11036 KB Correct
6 Correct 183 ms 11188 KB Correct
7 Correct 81 ms 7852 KB Correct
8 Correct 82 ms 7860 KB Correct
9 Correct 72 ms 8008 KB Correct
10 Incorrect 77 ms 7836 KB Not correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 764 KB Correct
2 Correct 196 ms 13232 KB Correct
3 Correct 230 ms 13796 KB Correct
4 Correct 117 ms 14720 KB Correct
5 Correct 110 ms 15348 KB Correct
6 Correct 190 ms 15240 KB Correct
7 Correct 88 ms 15688 KB Correct
8 Correct 84 ms 13752 KB Correct
9 Correct 222 ms 14072 KB Correct
10 Correct 219 ms 14728 KB Correct
11 Correct 157 ms 13556 KB Correct
12 Correct 115 ms 15904 KB Correct
13 Correct 282 ms 13980 KB Correct
14 Correct 87 ms 13120 KB Correct
15 Correct 88 ms 13716 KB Correct
16 Correct 215 ms 14764 KB Correct
17 Correct 227 ms 16476 KB Correct
18 Correct 126 ms 12864 KB Correct
19 Correct 95 ms 13668 KB Correct
20 Correct 143 ms 12880 KB Correct
21 Correct 84 ms 15340 KB Correct
22 Correct 84 ms 13884 KB Correct
23 Correct 219 ms 13880 KB Correct
24 Correct 208 ms 14324 KB Correct
25 Correct 116 ms 13552 KB Correct
26 Correct 97 ms 14644 KB Correct
27 Correct 93 ms 13220 KB Correct
28 Correct 80 ms 13900 KB Correct
29 Correct 95 ms 14336 KB Correct
30 Correct 216 ms 14412 KB Correct
31 Correct 217 ms 13072 KB Correct
32 Correct 87 ms 15600 KB Correct
33 Correct 229 ms 14372 KB Correct
34 Correct 222 ms 14812 KB Correct
35 Correct 91 ms 13444 KB Correct
36 Correct 91 ms 12796 KB Correct
37 Correct 212 ms 14356 KB Correct
38 Correct 221 ms 14396 KB Correct
39 Correct 244 ms 15232 KB Correct
40 Correct 162 ms 15568 KB Correct
41 Correct 208 ms 15344 KB Correct
42 Correct 86 ms 14828 KB Correct
43 Correct 90 ms 14652 KB Correct
44 Correct 209 ms 14348 KB Correct
45 Correct 228 ms 12644 KB Correct
46 Correct 99 ms 13480 KB Correct
47 Correct 88 ms 13792 KB Correct
48 Correct 115 ms 14572 KB Correct
49 Correct 84 ms 12860 KB Correct
50 Correct 86 ms 15108 KB Correct
51 Correct 76 ms 8184 KB Correct
52 Correct 78 ms 8000 KB Correct
53 Correct 84 ms 8144 KB Correct
54 Correct 97 ms 12096 KB Correct
55 Correct 126 ms 11036 KB Correct
56 Correct 183 ms 11188 KB Correct
57 Correct 81 ms 7852 KB Correct
58 Correct 82 ms 7860 KB Correct
59 Correct 72 ms 8008 KB Correct
60 Incorrect 77 ms 7836 KB Not correct
61 Halted 0 ms 0 KB -