답안 #603936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603936 2022-07-24T13:33:41 Z erekle 통행료 (IOI18_highway) C++17
51 / 100
298 ms 262144 KB
#include "highway.h"
#include <iostream>
#include <algorithm>
#include <cassert>

using namespace std;

vector<vector<pair<int, int>>> g;
vector<int> parent, edgeUp, depth;

void rootDFS(int node, int d = 0, int eUP = -1, int par = -1) {
  parent[node] = par;
  edgeUp[node] = eUP;
  depth[node] = d;
  for (auto [child, e] : g[node]) {
    if (child != par) rootDFS(child, d+1, e, node);
  }
}
void rootTree(int root, int N) {
  parent.resize(N);
  edgeUp.resize(N);
  depth.resize(N);
  rootDFS(root);
}
vector<int> nodesDepth(int d) {
  vector<int> v;
  for (int i = 0; i < (int)depth.size(); ++i) {
    if (depth[i] == d) v.push_back(i);
  }
  return v;
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
  g.resize(N);
  int M = U.size();
  for (int i = 0; i < M; ++i) {
    g[U[i]].emplace_back(V[i], i);
    g[V[i]].emplace_back(U[i], i);
  }
  vector<int> w(M);
  long long toll = ask(w);

  rootTree(0, N);
  // Find the depth of the lower of the two nodes
  int l = 0, r = *max_element(depth.begin(), depth.end()); // l < d <= r
  while (l+1 < r) {
    int mid = (l+r)/2;
    // set all nodes lower than depth mid to have B edges leading up
    for (int i = 0; i < N; ++i) {
      if (depth[i] > mid) w[edgeUp[i]] = 1;
    }
    long long res = ask(w);
    for (int i = 0; i < N; ++i) {
      if (depth[i] > mid) w[edgeUp[i]] = 0;
    }
    if (res == toll) r = mid;
    else l = mid;
  }
  int lowerDepth = r;

  auto findWithDepth = [&toll, &w](int depth) {
    vector<int> candidates = nodesDepth(depth);
    int l = 0, r = (int)candidates.size(); // in range [l, r)
    while (l+1 < r) {
      int mid = (l+r)/2;
      for (int i = mid; i < r; ++i) w[edgeUp[candidates[i]]] = 1, assert(edgeUp[candidates[i]] >= 0);
      long long res = ask(w);
      for (int i = mid; i < r; ++i) w[edgeUp[candidates[i]]] = 0;
      if (res == toll) r = mid;
      else l = mid;
    }
    return candidates[l];
  };

  // Find the lower of the two nodes (or one of them if they have the same depth)
  int S = findWithDepth(lowerDepth);

  // Find the other node by rooting the tree at the first node
  rootTree(S, N);
  assert(toll%A==0);
  int T = findWithDepth(toll/A);
  assert(depth[T] == toll/A);
  answer(S, T);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 11 ms 1232 KB Output is correct
3 Correct 131 ms 8712 KB Output is correct
4 Correct 108 ms 8700 KB Output is correct
5 Correct 127 ms 8836 KB Output is correct
6 Correct 98 ms 8620 KB Output is correct
7 Correct 99 ms 8656 KB Output is correct
8 Correct 125 ms 8708 KB Output is correct
9 Correct 102 ms 8708 KB Output is correct
10 Correct 100 ms 8644 KB Output is correct
11 Correct 114 ms 9060 KB Output is correct
12 Correct 121 ms 9568 KB Output is correct
13 Correct 146 ms 9176 KB Output is correct
14 Correct 106 ms 9308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1616 KB Output is correct
2 Correct 19 ms 2948 KB Output is correct
3 Correct 25 ms 4236 KB Output is correct
4 Correct 74 ms 12264 KB Output is correct
5 Correct 84 ms 12272 KB Output is correct
6 Correct 76 ms 12264 KB Output is correct
7 Correct 91 ms 12268 KB Output is correct
8 Correct 93 ms 12276 KB Output is correct
9 Correct 83 ms 12276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 13 ms 1136 KB Output is correct
3 Correct 76 ms 6776 KB Output is correct
4 Correct 111 ms 8596 KB Output is correct
5 Correct 100 ms 8652 KB Output is correct
6 Correct 99 ms 8664 KB Output is correct
7 Correct 123 ms 8644 KB Output is correct
8 Correct 136 ms 8664 KB Output is correct
9 Correct 138 ms 8632 KB Output is correct
10 Correct 132 ms 8828 KB Output is correct
11 Correct 153 ms 8932 KB Output is correct
12 Correct 119 ms 9592 KB Output is correct
13 Correct 141 ms 9256 KB Output is correct
14 Correct 129 ms 9540 KB Output is correct
15 Correct 107 ms 8592 KB Output is correct
16 Correct 113 ms 8604 KB Output is correct
17 Correct 151 ms 9356 KB Output is correct
18 Correct 157 ms 9408 KB Output is correct
19 Correct 99 ms 8640 KB Output is correct
20 Correct 107 ms 9892 KB Output is correct
21 Correct 124 ms 9648 KB Output is correct
22 Correct 90 ms 9640 KB Output is correct
23 Correct 100 ms 9256 KB Output is correct
24 Correct 116 ms 9560 KB Output is correct
25 Correct 145 ms 11960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 298 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 271 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -