#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
using ll = int;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define F first
#define S second
class Solver{
private:
ll k,n,ctr;
vvi adjList;
vi dfs_num, sz, label;
void DFS(ll v){
dfs_num[v] = ctr++;
for (auto u: adjList[v]){
if (dfs_num[u] == -1){
DFS(u);
sz[v] += sz[u];
}
}
label[v] = dfs_num[v]*1000+sz[v];
}
public:
Solver(ll k, ll n, vi u, vi v): k(k), n(n), adjList(n), dfs_num(n,-1), sz(n,1), label(n){
//cout << "hello\n";
for (ll i = 0; n-1 > i; i++){
adjList[u[i]].push_back(v[i]);
adjList[v[i]].push_back(u[i]);
}
//cout << "jello\n";
ctr = 0;
DFS(0);
}
vi get_labels(){
return label;
}
};
vi label(int n, int k, vi u, vi v) {
//cout << n << " " << k << endl;
Solver mySolver(k,n,u,v);
return mySolver.get_labels();
}
int find_next_station(int s, int t, std::vector<int> c) {
ii v = ii(s/1000,s%1000);
ii e = ii(t/1000,t%1000);
vii children(c.size());
for (ll i = 0; c.size() > i; i++){
children[i] = ii(c[i]/1000,c[i]%1000);
}
sort(children.begin(),children.end());
for (ll i = 1; children.size() > i; i++){
if (children[i].F+children[i].S > e.F && e.F >= children[i].F){
return children[i].F*1000+children[i].S;
}
}
return children[0].F*1000+children[0].S;
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:55:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
55 | for (ll i = 0; c.size() > i; i++){
| ~~~~~~~~~^~~
stations.cpp:59:33: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
59 | for (ll i = 1; children.size() > i; i++){
| ~~~~~~~~~~~~~~~~^~~
stations.cpp:52:5: warning: variable 'v' set but not used [-Wunused-but-set-variable]
52 | ii v = ii(s/1000,s%1000);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
512 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=6004 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1511 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
616 ms |
1008 KB |
Output is correct |
2 |
Correct |
557 ms |
1024 KB |
Output is correct |
3 |
Correct |
962 ms |
644 KB |
Output is correct |
4 |
Correct |
793 ms |
640 KB |
Output is correct |
5 |
Correct |
630 ms |
640 KB |
Output is correct |
6 |
Correct |
511 ms |
1024 KB |
Output is correct |
7 |
Correct |
507 ms |
772 KB |
Output is correct |
8 |
Correct |
3 ms |
652 KB |
Output is correct |
9 |
Correct |
4 ms |
772 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
589 ms |
640 KB |
Output is correct |
12 |
Correct |
473 ms |
1024 KB |
Output is correct |
13 |
Correct |
460 ms |
1000 KB |
Output is correct |
14 |
Correct |
461 ms |
768 KB |
Output is correct |
15 |
Correct |
58 ms |
892 KB |
Output is correct |
16 |
Correct |
74 ms |
848 KB |
Output is correct |
17 |
Correct |
114 ms |
808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
891 ms |
640 KB |
Output is correct |
2 |
Correct |
690 ms |
640 KB |
Output is correct |
3 |
Correct |
611 ms |
784 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
632 ms |
652 KB |
Output is correct |
8 |
Correct |
1113 ms |
644 KB |
Output is correct |
9 |
Correct |
756 ms |
640 KB |
Output is correct |
10 |
Correct |
590 ms |
648 KB |
Output is correct |
11 |
Correct |
7 ms |
644 KB |
Output is correct |
12 |
Correct |
7 ms |
648 KB |
Output is correct |
13 |
Correct |
5 ms |
644 KB |
Output is correct |
14 |
Correct |
3 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
514 ms |
640 KB |
Output is correct |
17 |
Correct |
611 ms |
648 KB |
Output is correct |
18 |
Correct |
513 ms |
784 KB |
Output is correct |
19 |
Correct |
523 ms |
644 KB |
Output is correct |
20 |
Correct |
620 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
582 ms |
1136 KB |
Partially correct |
2 |
Partially correct |
484 ms |
1132 KB |
Partially correct |
3 |
Partially correct |
1113 ms |
640 KB |
Partially correct |
4 |
Partially correct |
699 ms |
644 KB |
Partially correct |
5 |
Partially correct |
642 ms |
644 KB |
Partially correct |
6 |
Partially correct |
534 ms |
1024 KB |
Partially correct |
7 |
Partially correct |
509 ms |
788 KB |
Partially correct |
8 |
Partially correct |
3 ms |
1024 KB |
Partially correct |
9 |
Partially correct |
6 ms |
644 KB |
Partially correct |
10 |
Partially correct |
2 ms |
640 KB |
Partially correct |
11 |
Partially correct |
484 ms |
804 KB |
Partially correct |
12 |
Partially correct |
577 ms |
800 KB |
Partially correct |
13 |
Partially correct |
963 ms |
648 KB |
Partially correct |
14 |
Partially correct |
836 ms |
648 KB |
Partially correct |
15 |
Partially correct |
697 ms |
768 KB |
Partially correct |
16 |
Partially correct |
486 ms |
768 KB |
Partially correct |
17 |
Partially correct |
610 ms |
640 KB |
Partially correct |
18 |
Partially correct |
486 ms |
852 KB |
Partially correct |
19 |
Partially correct |
508 ms |
1128 KB |
Partially correct |
20 |
Partially correct |
496 ms |
768 KB |
Partially correct |
21 |
Partially correct |
59 ms |
892 KB |
Partially correct |
22 |
Partially correct |
96 ms |
768 KB |
Partially correct |
23 |
Partially correct |
143 ms |
824 KB |
Partially correct |
24 |
Partially correct |
5 ms |
640 KB |
Partially correct |
25 |
Partially correct |
7 ms |
640 KB |
Partially correct |
26 |
Partially correct |
5 ms |
640 KB |
Partially correct |
27 |
Partially correct |
2 ms |
640 KB |
Partially correct |
28 |
Partially correct |
1 ms |
644 KB |
Partially correct |
29 |
Partially correct |
521 ms |
772 KB |
Partially correct |
30 |
Partially correct |
501 ms |
640 KB |
Partially correct |
31 |
Partially correct |
518 ms |
648 KB |
Partially correct |
32 |
Partially correct |
513 ms |
912 KB |
Partially correct |
33 |
Partially correct |
530 ms |
648 KB |
Partially correct |
34 |
Partially correct |
328 ms |
760 KB |
Partially correct |
35 |
Partially correct |
434 ms |
1280 KB |
Partially correct |
36 |
Partially correct |
494 ms |
1008 KB |
Partially correct |
37 |
Partially correct |
444 ms |
792 KB |
Partially correct |
38 |
Partially correct |
484 ms |
760 KB |
Partially correct |
39 |
Partially correct |
449 ms |
768 KB |
Partially correct |
40 |
Partially correct |
471 ms |
792 KB |
Partially correct |
41 |
Partially correct |
454 ms |
1044 KB |
Partially correct |
42 |
Partially correct |
71 ms |
840 KB |
Partially correct |
43 |
Partially correct |
123 ms |
816 KB |
Partially correct |
44 |
Partially correct |
140 ms |
944 KB |
Partially correct |
45 |
Partially correct |
172 ms |
768 KB |
Partially correct |
46 |
Partially correct |
346 ms |
824 KB |
Partially correct |
47 |
Partially correct |
295 ms |
768 KB |
Partially correct |
48 |
Partially correct |
65 ms |
936 KB |
Partially correct |
49 |
Partially correct |
71 ms |
804 KB |
Partially correct |