Submission #329783

# Submission time Handle Problem Language Result Execution time Memory
329783 2020-11-22T14:18:02 Z chenwz Stations (IOI20_stations) C++14
100 / 100
1083 ms 1284 KB
#include "stations.h"
#include <vector>
using namespace std;
typedef vector<int> IVec;

void rec(int u, int fa, bool dfs_in, int &clock, const vector<IVec>& G, IVec& L) {
  if (dfs_in) L[u] = clock++;
  for (int i : G[u])
    if (i != fa) rec(i, u, !dfs_in, clock, G, L);
  if (!dfs_in) 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: s is in InClock. All the neighbors' label > s.
    if (t < s || t > c.back()) return c.back(); // t not in this subtree, go to parent.
    int v = 0; // t is in this subtree, Pick the smallest ch >= t
    return *lower_bound(c.begin(), c.end(), t);
  }
  if (t < c[0]) // Case 2: node s is in the post_order level.
    return c[0]; // t not in subtree
  if (t > s) return c[0]; // t not in this subtree, go to the root.
  int v = c.size() - 1;
  while (c[v] > t) v--;
  return c[v];
}

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++)
      |                   ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, IVec)':
stations.cpp:26:9: warning: unused variable 'v' [-Wunused-variable]
   26 |     int v = 0; // t is in this subtree, Pick the smallest ch >= t
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 496 ms 972 KB Output is correct
2 Correct 437 ms 972 KB Output is correct
3 Correct 843 ms 736 KB Output is correct
4 Correct 627 ms 880 KB Output is correct
5 Correct 605 ms 756 KB Output is correct
6 Correct 435 ms 884 KB Output is correct
7 Correct 429 ms 1000 KB Output is correct
8 Correct 3 ms 872 KB Output is correct
9 Correct 4 ms 736 KB Output is correct
10 Correct 1 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 442 ms 804 KB Output is correct
2 Correct 521 ms 800 KB Output is correct
3 Correct 875 ms 888 KB Output is correct
4 Correct 675 ms 880 KB Output is correct
5 Correct 633 ms 888 KB Output is correct
6 Correct 486 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 573 ms 884 KB Output is correct
2 Correct 675 ms 876 KB Output is correct
3 Correct 1083 ms 752 KB Output is correct
4 Correct 674 ms 736 KB Output is correct
5 Correct 686 ms 756 KB Output is correct
6 Correct 462 ms 1004 KB Output is correct
7 Correct 501 ms 1284 KB Output is correct
8 Correct 3 ms 756 KB Output is correct
9 Correct 2 ms 756 KB Output is correct
10 Correct 1 ms 884 KB Output is correct
11 Correct 672 ms 736 KB Output is correct
12 Correct 473 ms 1248 KB Output is correct
13 Correct 515 ms 1028 KB Output is correct
14 Correct 577 ms 756 KB Output is correct
15 Correct 63 ms 756 KB Output is correct
16 Correct 57 ms 756 KB Output is correct
17 Correct 114 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1035 ms 880 KB Output is correct
2 Correct 879 ms 756 KB Output is correct
3 Correct 583 ms 884 KB Output is correct
4 Correct 3 ms 756 KB Output is correct
5 Correct 4 ms 736 KB Output is correct
6 Correct 0 ms 756 KB Output is correct
7 Correct 626 ms 868 KB Output is correct
8 Correct 1020 ms 1040 KB Output is correct
9 Correct 647 ms 1016 KB Output is correct
10 Correct 688 ms 756 KB Output is correct
11 Correct 6 ms 880 KB Output is correct
12 Correct 7 ms 1032 KB Output is correct
13 Correct 5 ms 756 KB Output is correct
14 Correct 4 ms 736 KB Output is correct
15 Correct 2 ms 884 KB Output is correct
16 Correct 542 ms 884 KB Output is correct
17 Correct 652 ms 756 KB Output is correct
18 Correct 489 ms 884 KB Output is correct
19 Correct 539 ms 756 KB Output is correct
20 Correct 625 ms 1176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 599 ms 972 KB Output is correct
2 Correct 580 ms 884 KB Output is correct
3 Correct 1035 ms 884 KB Output is correct
4 Correct 767 ms 756 KB Output is correct
5 Correct 785 ms 816 KB Output is correct
6 Correct 559 ms 864 KB Output is correct
7 Correct 549 ms 1024 KB Output is correct
8 Correct 1 ms 736 KB Output is correct
9 Correct 4 ms 736 KB Output is correct
10 Correct 1 ms 928 KB Output is correct
11 Correct 510 ms 756 KB Output is correct
12 Correct 648 ms 756 KB Output is correct
13 Correct 1039 ms 732 KB Output is correct
14 Correct 884 ms 912 KB Output is correct
15 Correct 653 ms 1056 KB Output is correct
16 Correct 478 ms 736 KB Output is correct
17 Correct 676 ms 736 KB Output is correct
18 Correct 474 ms 992 KB Output is correct
19 Correct 479 ms 864 KB Output is correct
20 Correct 529 ms 736 KB Output is correct
21 Correct 62 ms 736 KB Output is correct
22 Correct 83 ms 832 KB Output is correct
23 Correct 160 ms 804 KB Output is correct
24 Correct 7 ms 756 KB Output is correct
25 Correct 7 ms 736 KB Output is correct
26 Correct 6 ms 736 KB Output is correct
27 Correct 4 ms 884 KB Output is correct
28 Correct 2 ms 736 KB Output is correct
29 Correct 502 ms 756 KB Output is correct
30 Correct 544 ms 884 KB Output is correct
31 Correct 606 ms 756 KB Output is correct
32 Correct 590 ms 756 KB Output is correct
33 Correct 726 ms 756 KB Output is correct
34 Correct 368 ms 884 KB Output is correct
35 Correct 472 ms 964 KB Output is correct
36 Correct 609 ms 964 KB Output is correct
37 Correct 492 ms 896 KB Output is correct
38 Correct 451 ms 1088 KB Output is correct
39 Correct 480 ms 780 KB Output is correct
40 Correct 451 ms 1232 KB Output is correct
41 Correct 534 ms 844 KB Output is correct
42 Correct 77 ms 756 KB Output is correct
43 Correct 105 ms 756 KB Output is correct
44 Correct 151 ms 756 KB Output is correct
45 Correct 180 ms 756 KB Output is correct
46 Correct 333 ms 736 KB Output is correct
47 Correct 360 ms 736 KB Output is correct
48 Correct 64 ms 748 KB Output is correct
49 Correct 68 ms 1164 KB Output is correct