Submission #660230

# Submission time Handle Problem Language Result Execution time Memory
660230 2022-11-21T09:02:52 Z MilosMilutinovic Amusement Park (JOI17_amusement_park) C++14
0 / 100
321 ms 15108 KB
#include "Joi.h"
#include <bits/stdc++.h>

using namespace std;

void Joi(int n, int m, int u[], int v[], long long x, int t) {
  vector<vector<int>> e(n);
  for (int i = 0; i < m; i++) {
    e[u[i]].push_back(v[i]);
    e[v[i]].push_back(u[i]);
  }
  for (int i = 0; i < n; i++) {
    sort(e[i].begin(), e[i].end());
  }
  vector<vector<int>> g(n);
  vector<bool> was(n);
  function<void(int, int)> MakeTree = [&](int v, int pv) {
    was[v] = true;
    for (int u : e[v]) {
      if (was[u]) {
        continue;
      }
      g[v].push_back(u);
      g[u].push_back(v);
      MakeTree(u, v);
    }
  };
  MakeTree(0, 0);
  const int L = 20;
  vector<vector<int>> pr(n, vector<int>(L));
  vector<int> dep(n);
  function<void(int, int)> Dfs = [&](int v, int pv) {
    pr[v][0] = pv;
    for (int j = 1; j < L; j++) {
      pr[v][j] = pr[pr[v][j - 1]][j - 1];
    }
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      dep[u] = dep[v] + 1;
      Dfs(u, v);
    }
  };
  Dfs(0, 0);
  auto LCA = [&](int x, int y) {
    if (dep[x] < dep[y]) {
      swap(x, y);
    }
    for (int i = L - 1; i >= 0; i--) {
      if (dep[pr[x][i]] >= dep[y]) {
        x = pr[x][i];
      }
    }
    if (x == y) {
      return x;
    }
    for (int i = L - 1; i >= 0; i--) {
      if (pr[x][i] != pr[y][i]) {
        x = pr[x][i];
        y = pr[y][i];
      }
    }
    return pr[x][0];
  };
  auto GetDist = [&](int x, int y) {
    return dep[x] + dep[y] - 2 * dep[LCA(x, y)];
  };
  vector<int> ver;
  function<void(int, int)> Go = [&](int v, int pv) {
    if (ver.size() == 60) {
      return;
    }
    ver.push_back(v);
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      Go(u, v);
    }
  };
  Go(0, 0);
  vector<vector<int>> ids(n);
  for (int x : ver) {
    ids[x] = ver;
  }
  vector<int> ans(n);
  for (int i = 0; i < 60; i++) {
    ans[ver[i]] = (x >> i & 1);
  }
  function<void(int, int)> Solve = [&](int v, int pv) {
    if (ids[v].empty()) {
      ids[v] = ids[pv];
      int idx = 0;
      for (int i = 1; i < 60; i++) {
        if (GetDist(ids[v][i], v) > GetDist(ids[v][idx], v)) {
          idx = i;
        }
      }
      ans[v] = ans[ids[v][idx]];
      ids[v][idx] = v;
    }
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      Solve(u, v);
    }
  };
  Solve(0, 0);
  for (int i = 0; i < n; i++) {
    MessageBoard(i, ans[i]);
  }
}
#include "Ioi.h"
#include <bits/stdc++.h>

using namespace std;

long long Ioi(int n, int m, int u[], int v[], int p, int me, int t) {
  vector<vector<int>> e(n);
  for (int i = 0; i < m; i++) {
    e[u[i]].push_back(v[i]);
    e[v[i]].push_back(u[i]);
  }
  for (int i = 0; i < n; i++) {
    sort(e[i].begin(), e[i].end());
  }
  vector<vector<int>> g(n);
  vector<bool> was(n);
  function<void(int, int)> MakeTree = [&](int v, int pv) {
    was[v] = true;
    for (int u : e[v]) {
      if (was[u]) {
        continue;
      }
      g[v].push_back(u);
      g[u].push_back(v);
      MakeTree(u, v);
    }
  };
  MakeTree(0, 0);
  const int L = 20;
  vector<vector<int>> pr(n, vector<int>(L));
  vector<int> dep(n);
  function<void(int, int)> Dfs = [&](int v, int pv) {
    pr[v][0] = pv;
    for (int j = 1; j < L; j++) {
      pr[v][j] = pr[pr[v][j - 1]][j - 1];
    }
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      dep[u] = dep[v] + 1;
      Dfs(u, v);
    }
  };
  Dfs(0, 0);
  auto LCA = [&](int x, int y) {
    if (dep[x] < dep[y]) {
      swap(x, y);
    }
    for (int i = L - 1; i >= 0; i--) {
      if (dep[pr[x][i]] >= dep[y]) {
        x = pr[x][i];
      }
    }
    if (x == y) {
      return x;
    }
    for (int i = L - 1; i >= 0; i--) {
      if (pr[x][i] != pr[y][i]) {
        x = pr[x][i];
        y = pr[y][i];
      }
    }
    return pr[x][0];
  };
  auto GetDist = [&](int x, int y) {
    return dep[x] + dep[y] - 2 * dep[LCA(x, y)];
  };
  vector<int> ver;
  function<void(int, int)> Go = [&](int v, int pv) {
    if (ver.size() == 60) {
      return;
    }
    ver.push_back(v);
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      Go(u, v);
    }
  };
  Go(0, 0);
  vector<vector<int>> ids(n);
  for (int x : ver) {
    ids[x] = ver;
  }
  function<void(int, int)> Solve = [&](int v, int pv) {
    if (ids[v].empty()) {
      ids[v] = ids[pv];
      int idx = 0;
      for (int i = 1; i < 60; i++) {
        if (GetDist(ids[v][i], v) > GetDist(ids[v][idx], v)) {
          idx = i;
        }
      }
      ids[v][idx] = v;
    }
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      Solve(u, v);
    }
  };
  Solve(0, 0);
  vector<int> bit(n, -1);
  for (int i = 0; i < 60; i++) {
    bit[ids[p][i]] = i;
  }
  vector<int> f(n);
  f[p] = me;
  function<void(int, int)> FindBits = [&](int v, int pv) {
    for (int u : g[v]) {
      if (bit[u] == -1) {
        continue;
      }
      f[u] = Move(u);
      FindBits(u, v);
      f[v] = Move(v);
    }
  };
  FindBits(p, p);
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if (bit[i] != -1) {
      res += (1LL << bit[i]) * f[i];
    }
  }
  return res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2560 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 300 ms 15092 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2556 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 298 ms 15044 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 321 ms 15108 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -