Submission #329787

# Submission time Handle Problem Language Result Execution time Memory
329787 2020-11-22T14:25:04 Z chenwz Stations (IOI20_stations) C++14
100 / 100
997 ms 1092 KB
#include "stations.h"
#include <vector>
#include <algorithm>
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 (size_t 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.
    return *lower_bound(c.begin(), c.end(), t); // t is in this subtree, Pick the smallest ch >= 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];
  return *(upper_bound(c.begin(), c.end(), t) - 1);
}
# Verdict Execution time Memory Grader output
1 Correct 551 ms 972 KB Output is correct
2 Correct 431 ms 884 KB Output is correct
3 Correct 856 ms 804 KB Output is correct
4 Correct 658 ms 880 KB Output is correct
5 Correct 604 ms 736 KB Output is correct
6 Correct 460 ms 884 KB Output is correct
7 Correct 397 ms 864 KB Output is correct
8 Correct 2 ms 880 KB Output is correct
9 Correct 4 ms 736 KB Output is correct
10 Correct 0 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 427 ms 736 KB Output is correct
2 Correct 530 ms 820 KB Output is correct
3 Correct 936 ms 880 KB Output is correct
4 Correct 756 ms 1008 KB Output is correct
5 Correct 571 ms 736 KB Output is correct
6 Correct 454 ms 884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 621 ms 908 KB Output is correct
2 Correct 497 ms 1092 KB Output is correct
3 Correct 985 ms 736 KB Output is correct
4 Correct 851 ms 992 KB Output is correct
5 Correct 648 ms 880 KB Output is correct
6 Correct 489 ms 864 KB Output is correct
7 Correct 436 ms 884 KB Output is correct
8 Correct 2 ms 888 KB Output is correct
9 Correct 3 ms 884 KB Output is correct
10 Correct 0 ms 756 KB Output is correct
11 Correct 584 ms 888 KB Output is correct
12 Correct 440 ms 1080 KB Output is correct
13 Correct 481 ms 884 KB Output is correct
14 Correct 435 ms 884 KB Output is correct
15 Correct 53 ms 872 KB Output is correct
16 Correct 77 ms 760 KB Output is correct
17 Correct 107 ms 756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 857 ms 804 KB Output is correct
2 Correct 731 ms 1012 KB Output is correct
3 Correct 600 ms 1008 KB Output is correct
4 Correct 3 ms 888 KB Output is correct
5 Correct 4 ms 756 KB Output is correct
6 Correct 1 ms 796 KB Output is correct
7 Correct 711 ms 736 KB Output is correct
8 Correct 971 ms 880 KB Output is correct
9 Correct 835 ms 736 KB Output is correct
10 Correct 701 ms 884 KB Output is correct
11 Correct 5 ms 888 KB Output is correct
12 Correct 5 ms 736 KB Output is correct
13 Correct 5 ms 1008 KB Output is correct
14 Correct 4 ms 880 KB Output is correct
15 Correct 1 ms 888 KB Output is correct
16 Correct 649 ms 736 KB Output is correct
17 Correct 673 ms 1008 KB Output is correct
18 Correct 512 ms 748 KB Output is correct
19 Correct 475 ms 888 KB Output is correct
20 Correct 538 ms 880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 574 ms 916 KB Output is correct
2 Correct 475 ms 984 KB Output is correct
3 Correct 997 ms 736 KB Output is correct
4 Correct 741 ms 880 KB Output is correct
5 Correct 672 ms 1008 KB Output is correct
6 Correct 515 ms 864 KB Output is correct
7 Correct 408 ms 736 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 3 ms 756 KB Output is correct
10 Correct 0 ms 880 KB Output is correct
11 Correct 415 ms 812 KB Output is correct
12 Correct 549 ms 916 KB Output is correct
13 Correct 863 ms 1008 KB Output is correct
14 Correct 678 ms 804 KB Output is correct
15 Correct 580 ms 736 KB Output is correct
16 Correct 444 ms 808 KB Output is correct
17 Correct 601 ms 880 KB Output is correct
18 Correct 445 ms 864 KB Output is correct
19 Correct 477 ms 980 KB Output is correct
20 Correct 450 ms 808 KB Output is correct
21 Correct 54 ms 872 KB Output is correct
22 Correct 72 ms 832 KB Output is correct
23 Correct 107 ms 928 KB Output is correct
24 Correct 4 ms 880 KB Output is correct
25 Correct 5 ms 756 KB Output is correct
26 Correct 3 ms 756 KB Output is correct
27 Correct 3 ms 888 KB Output is correct
28 Correct 2 ms 888 KB Output is correct
29 Correct 562 ms 756 KB Output is correct
30 Correct 541 ms 1012 KB Output is correct
31 Correct 502 ms 880 KB Output is correct
32 Correct 568 ms 880 KB Output is correct
33 Correct 542 ms 888 KB Output is correct
34 Correct 309 ms 992 KB Output is correct
35 Correct 468 ms 992 KB Output is correct
36 Correct 535 ms 984 KB Output is correct
37 Correct 497 ms 864 KB Output is correct
38 Correct 616 ms 756 KB Output is correct
39 Correct 595 ms 892 KB Output is correct
40 Correct 451 ms 844 KB Output is correct
41 Correct 581 ms 776 KB Output is correct
42 Correct 58 ms 756 KB Output is correct
43 Correct 103 ms 756 KB Output is correct
44 Correct 128 ms 1012 KB Output is correct
45 Correct 169 ms 864 KB Output is correct
46 Correct 320 ms 756 KB Output is correct
47 Correct 306 ms 756 KB Output is correct
48 Correct 70 ms 736 KB Output is correct
49 Correct 57 ms 864 KB Output is correct