Submission #387825

# Submission time Handle Problem Language Result Execution time Memory
387825 2021-04-09T08:59:21 Z WLZ Stations (IOI20_stations) C++14
100 / 100
897 ms 852 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

int dfs_cnt = 0;
vector< vector<int> > g;
vector<int> d, dfs_in, dfs_out;

void dfs(int u, int p) {
  dfs_in[u] = dfs_cnt++;
  for (auto& v : g[u]) {
    if (v != p) {
      d[v] = d[u] + 1;
      dfs(v, u);
    }
  }
  dfs_out[u] = dfs_cnt++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
  g.assign(n, {});
  d.assign(n, 0);
  for (int i = 0; i < n - 1; i++) {
    g[u[i]].push_back(v[i]);
    g[v[i]].push_back(u[i]);
  }
  dfs_in.assign(n, 0); dfs_out.assign(n, 0);
  dfs(0, -1);
  set<int> st;
  for (int i = 0; i < n; i++) {
    if (d[i] % 2 == 0) st.insert(dfs_in[i]);
    else st.insert(dfs_out[i]);
  }
  int cur = 0;
  map<int, int> mp;
  for (auto& x : st) mp[x] = cur++;
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    if (d[i] % 2 == 0) ans[i] = mp[dfs_in[i]];
    else ans[i] = mp[dfs_out[i]];
  }
  return ans;
}

int find_next_station(int s, int t, vector<int> c) {
  for (auto& x : c) if (x == t) return t;
  sort(c.begin(), c.end());
  if (s < c[0]) { // in
    for (int i = 0; i < (int) c.size() - 1; i++) if (s < t && t < c[i]) return c[i];
    return c.back();
  } else { // out
    for (int i = (int) c.size() - 1; i >= 1; i--) if (c[i] < t && t < s) return c[i];
    return c[0];
  }
}
# Verdict Execution time Memory Grader output
1 Correct 544 ms 668 KB Output is correct
2 Correct 441 ms 656 KB Output is correct
3 Correct 850 ms 400 KB Output is correct
4 Correct 634 ms 472 KB Output is correct
5 Correct 572 ms 400 KB Output is correct
6 Correct 517 ms 656 KB Output is correct
7 Correct 393 ms 608 KB Output is correct
8 Correct 3 ms 472 KB Output is correct
9 Correct 4 ms 480 KB Output is correct
10 Correct 1 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 448 ms 660 KB Output is correct
2 Correct 515 ms 612 KB Output is correct
3 Correct 897 ms 400 KB Output is correct
4 Correct 640 ms 492 KB Output is correct
5 Correct 629 ms 400 KB Output is correct
6 Correct 458 ms 656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 532 ms 656 KB Output is correct
2 Correct 445 ms 608 KB Output is correct
3 Correct 878 ms 400 KB Output is correct
4 Correct 612 ms 400 KB Output is correct
5 Correct 495 ms 400 KB Output is correct
6 Correct 561 ms 776 KB Output is correct
7 Correct 411 ms 656 KB Output is correct
8 Correct 3 ms 400 KB Output is correct
9 Correct 4 ms 472 KB Output is correct
10 Correct 2 ms 464 KB Output is correct
11 Correct 562 ms 492 KB Output is correct
12 Correct 454 ms 740 KB Output is correct
13 Correct 487 ms 780 KB Output is correct
14 Correct 438 ms 616 KB Output is correct
15 Correct 50 ms 400 KB Output is correct
16 Correct 64 ms 580 KB Output is correct
17 Correct 121 ms 656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 840 ms 488 KB Output is correct
2 Correct 604 ms 528 KB Output is correct
3 Correct 572 ms 400 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 4 ms 472 KB Output is correct
6 Correct 2 ms 472 KB Output is correct
7 Correct 602 ms 488 KB Output is correct
8 Correct 849 ms 520 KB Output is correct
9 Correct 637 ms 404 KB Output is correct
10 Correct 583 ms 492 KB Output is correct
11 Correct 5 ms 472 KB Output is correct
12 Correct 5 ms 472 KB Output is correct
13 Correct 5 ms 472 KB Output is correct
14 Correct 4 ms 476 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 493 ms 496 KB Output is correct
17 Correct 486 ms 400 KB Output is correct
18 Correct 463 ms 488 KB Output is correct
19 Correct 500 ms 492 KB Output is correct
20 Correct 474 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 462 ms 608 KB Output is correct
2 Correct 429 ms 624 KB Output is correct
3 Correct 844 ms 520 KB Output is correct
4 Correct 631 ms 400 KB Output is correct
5 Correct 584 ms 400 KB Output is correct
6 Correct 448 ms 616 KB Output is correct
7 Correct 443 ms 656 KB Output is correct
8 Correct 2 ms 480 KB Output is correct
9 Correct 4 ms 480 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 441 ms 784 KB Output is correct
12 Correct 531 ms 612 KB Output is correct
13 Correct 842 ms 488 KB Output is correct
14 Correct 604 ms 400 KB Output is correct
15 Correct 628 ms 528 KB Output is correct
16 Correct 412 ms 612 KB Output is correct
17 Correct 584 ms 720 KB Output is correct
18 Correct 450 ms 740 KB Output is correct
19 Correct 459 ms 612 KB Output is correct
20 Correct 435 ms 620 KB Output is correct
21 Correct 54 ms 400 KB Output is correct
22 Correct 67 ms 584 KB Output is correct
23 Correct 100 ms 656 KB Output is correct
24 Correct 5 ms 472 KB Output is correct
25 Correct 6 ms 468 KB Output is correct
26 Correct 5 ms 476 KB Output is correct
27 Correct 4 ms 480 KB Output is correct
28 Correct 2 ms 480 KB Output is correct
29 Correct 497 ms 428 KB Output is correct
30 Correct 497 ms 528 KB Output is correct
31 Correct 491 ms 400 KB Output is correct
32 Correct 478 ms 400 KB Output is correct
33 Correct 473 ms 428 KB Output is correct
34 Correct 277 ms 656 KB Output is correct
35 Correct 400 ms 816 KB Output is correct
36 Correct 439 ms 620 KB Output is correct
37 Correct 444 ms 716 KB Output is correct
38 Correct 376 ms 688 KB Output is correct
39 Correct 439 ms 676 KB Output is correct
40 Correct 413 ms 700 KB Output is correct
41 Correct 437 ms 844 KB Output is correct
42 Correct 62 ms 528 KB Output is correct
43 Correct 103 ms 676 KB Output is correct
44 Correct 125 ms 656 KB Output is correct
45 Correct 156 ms 656 KB Output is correct
46 Correct 302 ms 600 KB Output is correct
47 Correct 309 ms 648 KB Output is correct
48 Correct 64 ms 676 KB Output is correct
49 Correct 62 ms 852 KB Output is correct