Submission #309718

# Submission time Handle Problem Language Result Execution time Memory
309718 2020-10-04T11:24:55 Z kris01 Stations (IOI20_stations) C++14
100 / 100
977 ms 1132 KB
#include "stations.h"
#include <bits/stdc++.h>
#define pii pair <int,int>
#define mp make_pair
using namespace std;
vector < vector <int> > Adj; // Adjacency List for the graph
vector <int> Tin,Tout; // Entry and Exit times respectively
vector <int> Depth; // Depth of a given node from the root (node 1)
int timer = 0;

void DFS(int v,int p) {
    Tin[v] = timer++;
    for (int x : Adj[v]) {
     if (x == p) continue;
     Depth[x] = Depth[v] + 1;
     DFS(x,v);
    }
    Tout[v] = timer++;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
	Adj.clear();
	Tin.clear();
	Tout.clear();
	Depth.clear();
	Adj.resize(n);
	Tin.resize(n);
	Tout.resize(n);
	Depth.resize(n+1,0);
	for (int i = 0;i < n-1;i++) {
        int a = u[i];
        int b = v[i];
        Adj[a].push_back(b);
        Adj[b].push_back(a);
	}
    timer = 0;
    DFS(0,-1);
    vector <pair <int,int> > LBLS(n); // Dummy vector to sort the labels
    for (int i = 0;i < n;i++) {
        if (Depth[i] % 2 == 0) {
         LBLS[i] = mp(Tin[i],i);
        } else {
         LBLS[i] = mp(Tout[i],i);
        }
    }
    sort(LBLS.begin(),LBLS.end());
    for (int i = 0;i < n;i++) {
     labels[LBLS[i].second] = i;
    }
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	sort(c.begin(),c.end());
	if (s < c[0]) {
     if (t < s || c.size() == 1 || t > c[c.size() - 2])
            return c.back();
        return *lower_bound(c.begin(), c.end(), t);
	} else {
      auto it = upper_bound(c.begin(),c.end(),t);
      if (c.size() == 1 || t > s || t < c[1]) {
        return c[0];
      }
       return *(upper_bound(c.begin(), c.end(), t) - 1);
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:61:12: warning: variable 'it' set but not used [-Wunused-but-set-variable]
   61 |       auto it = upper_bound(c.begin(),c.end(),t);
      |            ^~
# Verdict Execution time Memory Grader output
1 Correct 562 ms 1024 KB Output is correct
2 Correct 466 ms 1024 KB Output is correct
3 Correct 889 ms 640 KB Output is correct
4 Correct 690 ms 640 KB Output is correct
5 Correct 608 ms 640 KB Output is correct
6 Correct 465 ms 1024 KB Output is correct
7 Correct 461 ms 768 KB Output is correct
8 Correct 2 ms 648 KB Output is correct
9 Correct 5 ms 648 KB Output is correct
10 Correct 1 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 464 ms 800 KB Output is correct
2 Correct 542 ms 804 KB Output is correct
3 Correct 886 ms 644 KB Output is correct
4 Correct 675 ms 768 KB Output is correct
5 Correct 791 ms 768 KB Output is correct
6 Correct 500 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 569 ms 1024 KB Output is correct
2 Correct 510 ms 1024 KB Output is correct
3 Correct 977 ms 760 KB Output is correct
4 Correct 704 ms 648 KB Output is correct
5 Correct 588 ms 640 KB Output is correct
6 Correct 558 ms 1008 KB Output is correct
7 Correct 475 ms 768 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 675 ms 640 KB Output is correct
12 Correct 573 ms 1024 KB Output is correct
13 Correct 514 ms 1024 KB Output is correct
14 Correct 450 ms 808 KB Output is correct
15 Correct 60 ms 768 KB Output is correct
16 Correct 72 ms 836 KB Output is correct
17 Correct 108 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 870 ms 760 KB Output is correct
2 Correct 658 ms 652 KB Output is correct
3 Correct 600 ms 640 KB Output is correct
4 Correct 1 ms 644 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 1 ms 644 KB Output is correct
7 Correct 609 ms 756 KB Output is correct
8 Correct 908 ms 644 KB Output is correct
9 Correct 762 ms 644 KB Output is correct
10 Correct 640 ms 772 KB Output is correct
11 Correct 7 ms 644 KB Output is correct
12 Correct 7 ms 648 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 2 ms 656 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 512 ms 640 KB Output is correct
17 Correct 573 ms 640 KB Output is correct
18 Correct 524 ms 640 KB Output is correct
19 Correct 548 ms 656 KB Output is correct
20 Correct 551 ms 900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 555 ms 1024 KB Output is correct
2 Correct 472 ms 1024 KB Output is correct
3 Correct 977 ms 644 KB Output is correct
4 Correct 688 ms 640 KB Output is correct
5 Correct 632 ms 768 KB Output is correct
6 Correct 460 ms 1024 KB Output is correct
7 Correct 463 ms 768 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 4 ms 780 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 524 ms 816 KB Output is correct
12 Correct 574 ms 816 KB Output is correct
13 Correct 976 ms 656 KB Output is correct
14 Correct 663 ms 640 KB Output is correct
15 Correct 787 ms 640 KB Output is correct
16 Correct 490 ms 792 KB Output is correct
17 Correct 621 ms 652 KB Output is correct
18 Correct 548 ms 1024 KB Output is correct
19 Correct 474 ms 1132 KB Output is correct
20 Correct 496 ms 816 KB Output is correct
21 Correct 66 ms 892 KB Output is correct
22 Correct 77 ms 840 KB Output is correct
23 Correct 118 ms 936 KB Output is correct
24 Correct 6 ms 640 KB Output is correct
25 Correct 5 ms 652 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 1 ms 640 KB Output is correct
29 Correct 559 ms 784 KB Output is correct
30 Correct 517 ms 656 KB Output is correct
31 Correct 510 ms 784 KB Output is correct
32 Correct 493 ms 776 KB Output is correct
33 Correct 556 ms 648 KB Output is correct
34 Correct 331 ms 1008 KB Output is correct
35 Correct 468 ms 1024 KB Output is correct
36 Correct 467 ms 1024 KB Output is correct
37 Correct 447 ms 1024 KB Output is correct
38 Correct 459 ms 1024 KB Output is correct
39 Correct 460 ms 768 KB Output is correct
40 Correct 435 ms 888 KB Output is correct
41 Correct 466 ms 776 KB Output is correct
42 Correct 69 ms 768 KB Output is correct
43 Correct 111 ms 796 KB Output is correct
44 Correct 133 ms 808 KB Output is correct
45 Correct 169 ms 768 KB Output is correct
46 Correct 319 ms 808 KB Output is correct
47 Correct 309 ms 776 KB Output is correct
48 Correct 72 ms 816 KB Output is correct
49 Correct 63 ms 768 KB Output is correct