Submission #329728

# Submission time Handle Problem Language Result Execution time Memory
329728 2020-11-22T08:47:33 Z chenwz Stations (IOI20_stations) C++14
100 / 100
1006 ms 1140 KB
#include "stations.h"
#include <vector>
using namespace std;
typedef vector<int> IVec;

void rec(int u, int fa, bool pre_order, int &clock, const vector<IVec>& G, IVec& L) {
  if (pre_order) L[u] = clock++;
  for (int i : G[u])
    if (i != fa) rec(i, u, !pre_order, clock, G, L);
  if (!pre_order) L[u] = clock++;
}

IVec label(int n, int k, IVec u, IVec v) {
  IVec L(n);
  vector<IVec> G(n, IVec());
  for (int i = 0; i < u.size(); i++)
    G[u[i]].push_back(v[i]), G[v[i]].push_back(u[i]);
  int clock = 0;
  rec(0, -1, true, clock, G, L);
  return L;
}

int find_next_station(int s, int t, IVec c) {
  if (c[0] > s) {
    // Case 1: node s is in pre_order level.
    // All the neighbors are higher than s.

    if (t < s) {
      // The target is smaller than the source.
      // The target is definitely not in this subtree, go to parent.
      return c.back();
    }

    if (t > c.back()) {
      // The target is higher than the largest neighbor.
      // The target cannot be in this subtree, go to parent.
      return c.back();
    }

    // The target is in this subtree.
    // Pick the smallest child that's at least the target.
    int next = 0;
    while (c[next] < t) next++;
    return c[next];
  }


  // Case 2: node s is in the post_order level.
  if (t < c[0]) {
    // The target is smaller than the pre_order root c[0],
    // thus not in this subtree, go to the root.
    return c[0];
  }

  if (t > s) {
    // The target is higher than this post_order value.
    // Thus it's not in this subtree, go to the root.
    return c[0];
  }

  int next = c.size() - 1;
  while (c[next] > t) next--;
  return c[next];
}

Compilation message

stations.cpp: In function 'IVec label(int, int, IVec, IVec)':
stations.cpp:16:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   for (int i = 0; i < u.size(); i++)
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 557 ms 764 KB Output is correct
2 Correct 469 ms 876 KB Output is correct
3 Correct 894 ms 756 KB Output is correct
4 Correct 688 ms 756 KB Output is correct
5 Correct 573 ms 756 KB Output is correct
6 Correct 476 ms 1044 KB Output is correct
7 Correct 433 ms 884 KB Output is correct
8 Correct 3 ms 920 KB Output is correct
9 Correct 2 ms 776 KB Output is correct
10 Correct 0 ms 756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 547 ms 756 KB Output is correct
2 Correct 560 ms 736 KB Output is correct
3 Correct 957 ms 756 KB Output is correct
4 Correct 694 ms 1056 KB Output is correct
5 Correct 632 ms 884 KB Output is correct
6 Correct 482 ms 1044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 547 ms 972 KB Output is correct
2 Correct 572 ms 956 KB Output is correct
3 Correct 1006 ms 1012 KB Output is correct
4 Correct 701 ms 992 KB Output is correct
5 Correct 592 ms 756 KB Output is correct
6 Correct 507 ms 864 KB Output is correct
7 Correct 478 ms 1016 KB Output is correct
8 Correct 3 ms 756 KB Output is correct
9 Correct 5 ms 756 KB Output is correct
10 Correct 1 ms 756 KB Output is correct
11 Correct 606 ms 660 KB Output is correct
12 Correct 475 ms 1044 KB Output is correct
13 Correct 520 ms 992 KB Output is correct
14 Correct 453 ms 1012 KB Output is correct
15 Correct 52 ms 920 KB Output is correct
16 Correct 87 ms 756 KB Output is correct
17 Correct 108 ms 756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 942 ms 756 KB Output is correct
2 Correct 765 ms 880 KB Output is correct
3 Correct 622 ms 756 KB Output is correct
4 Correct 3 ms 736 KB Output is correct
5 Correct 4 ms 756 KB Output is correct
6 Correct 2 ms 736 KB Output is correct
7 Correct 685 ms 736 KB Output is correct
8 Correct 989 ms 756 KB Output is correct
9 Correct 700 ms 860 KB Output is correct
10 Correct 726 ms 736 KB Output is correct
11 Correct 6 ms 880 KB Output is correct
12 Correct 5 ms 756 KB Output is correct
13 Correct 5 ms 756 KB Output is correct
14 Correct 3 ms 880 KB Output is correct
15 Correct 1 ms 736 KB Output is correct
16 Correct 494 ms 756 KB Output is correct
17 Correct 510 ms 1008 KB Output is correct
18 Correct 520 ms 1008 KB Output is correct
19 Correct 505 ms 880 KB Output is correct
20 Correct 503 ms 880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 525 ms 864 KB Output is correct
2 Correct 447 ms 984 KB Output is correct
3 Correct 850 ms 756 KB Output is correct
4 Correct 625 ms 880 KB Output is correct
5 Correct 581 ms 880 KB Output is correct
6 Correct 479 ms 972 KB Output is correct
7 Correct 442 ms 864 KB Output is correct
8 Correct 2 ms 920 KB Output is correct
9 Correct 3 ms 756 KB Output is correct
10 Correct 1 ms 756 KB Output is correct
11 Correct 485 ms 756 KB Output is correct
12 Correct 455 ms 808 KB Output is correct
13 Correct 994 ms 736 KB Output is correct
14 Correct 688 ms 756 KB Output is correct
15 Correct 710 ms 736 KB Output is correct
16 Correct 537 ms 756 KB Output is correct
17 Correct 765 ms 756 KB Output is correct
18 Correct 532 ms 992 KB Output is correct
19 Correct 477 ms 988 KB Output is correct
20 Correct 552 ms 808 KB Output is correct
21 Correct 58 ms 668 KB Output is correct
22 Correct 71 ms 824 KB Output is correct
23 Correct 124 ms 768 KB Output is correct
24 Correct 5 ms 756 KB Output is correct
25 Correct 7 ms 768 KB Output is correct
26 Correct 7 ms 880 KB Output is correct
27 Correct 6 ms 880 KB Output is correct
28 Correct 2 ms 756 KB Output is correct
29 Correct 588 ms 880 KB Output is correct
30 Correct 514 ms 1140 KB Output is correct
31 Correct 460 ms 788 KB Output is correct
32 Correct 599 ms 736 KB Output is correct
33 Correct 557 ms 736 KB Output is correct
34 Correct 322 ms 992 KB Output is correct
35 Correct 441 ms 864 KB Output is correct
36 Correct 456 ms 884 KB Output is correct
37 Correct 542 ms 820 KB Output is correct
38 Correct 498 ms 788 KB Output is correct
39 Correct 439 ms 868 KB Output is correct
40 Correct 487 ms 868 KB Output is correct
41 Correct 487 ms 884 KB Output is correct
42 Correct 77 ms 820 KB Output is correct
43 Correct 126 ms 808 KB Output is correct
44 Correct 144 ms 804 KB Output is correct
45 Correct 159 ms 748 KB Output is correct
46 Correct 379 ms 800 KB Output is correct
47 Correct 328 ms 764 KB Output is correct
48 Correct 76 ms 796 KB Output is correct
49 Correct 73 ms 864 KB Output is correct