#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int)((x).size())
#define pb push_back
#define REP(i,n) for (int i = 0; i<n; ++i)
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){ cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y){ cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
const int maxn = 1e3+5;
vector<int> g[maxn];
std::vector<int> re;
set<int> here[maxn];
int sz[maxn];
void szdfs(int v, int p) {
sz[v] =1;
for (int u : g[v]) {
if (u == p) continue;
szdfs(u,v);
sz[v] += sz[u];
}
}
void dfs(int v, int p, bool big) {
sort(ALL(g[v]), [&](int a, int b){return sz[a] < sz[b];});
if (g[v].back() == p) g[v].pop_back();
if( big) {
re[v] = *(here[v].rbegin());
}else{
re[v] = *(here[v].begin());
}
here[v].erase(re[v]);
for (int u : g[v]) {
assert(u != p);
if (u == g[v].back()) here[u].swap(here[v]);
else{
REP(j, sz[u]) {
here[u].insert(*here[v].begin());
here[v].erase(here[v].begin());
}
}
dfs(u,v,big^1);
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
// cout<<"HIHOEIHFOI"<<endl;
re.resize(n);
// return re;
REP(i,n) g[i].clear();
REP(i,n) here[i].clear();
REP(i,n-1) {
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
}
szdfs(0,-1);
REP(i,n) here[0].insert(i);
dfs(0,-1,0);
// for (int i = 0; i<n; ++i) {
// cout<<i<<": "<<re[i]<<endl;
// }
return re;
}
int find_next_station(int s, int t, std::vector<int> c) {
// return c[0];
if (SZ(c) == 1) {
return c[0];
}
sort(ALL(c));
// if (SZ(c) == 2) {
// if (c[0] > s && c[1] > s) {
// return min(c[0], c[1]);
// }else{
// assert(c[0] < s && c[1] < s);
// return max(c[0], c[1]);
// }
// }
int numbig = 0;
for (int b : c) {
if (b > s) numbig++;
}
// cout<<"Hey"<<numbig<<endl;
if (numbig > 0) {
// bigs are the upper bound
int prv = s;
for (int b : c) {
if (t<=b && t> prv) {
return b;
}
prv = b;
}
return c.back();
// return the last one
}else{
// smalls are the lower bound
// cout<<"smol!"<<endl;
reverse(ALL(c));
int prv = s;
for (int b : c) {
if (t>=b && t< prv) {
return b;
}
prv = b;
}
return c.back();
}
}
/*
1
6 1000
0 1
1 2
2 3
3 4
1 5
4
3 5 -1
0 4 -1
1 4 -1
2 0 -1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
692 ms |
956 KB |
Output is correct |
2 |
Correct |
510 ms |
820 KB |
Output is correct |
3 |
Correct |
1047 ms |
656 KB |
Output is correct |
4 |
Correct |
698 ms |
688 KB |
Output is correct |
5 |
Correct |
710 ms |
656 KB |
Output is correct |
6 |
Correct |
568 ms |
776 KB |
Output is correct |
7 |
Correct |
487 ms |
784 KB |
Output is correct |
8 |
Correct |
3 ms |
728 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
555 ms |
680 KB |
Output is correct |
2 |
Correct |
632 ms |
692 KB |
Output is correct |
3 |
Correct |
880 ms |
784 KB |
Output is correct |
4 |
Correct |
948 ms |
696 KB |
Output is correct |
5 |
Correct |
759 ms |
704 KB |
Output is correct |
6 |
Correct |
555 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
673 ms |
784 KB |
Output is correct |
2 |
Correct |
565 ms |
820 KB |
Output is correct |
3 |
Correct |
1001 ms |
656 KB |
Output is correct |
4 |
Correct |
753 ms |
656 KB |
Output is correct |
5 |
Correct |
751 ms |
720 KB |
Output is correct |
6 |
Correct |
478 ms |
784 KB |
Output is correct |
7 |
Correct |
441 ms |
808 KB |
Output is correct |
8 |
Correct |
3 ms |
724 KB |
Output is correct |
9 |
Correct |
6 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
660 ms |
692 KB |
Output is correct |
12 |
Correct |
504 ms |
800 KB |
Output is correct |
13 |
Correct |
601 ms |
936 KB |
Output is correct |
14 |
Correct |
638 ms |
692 KB |
Output is correct |
15 |
Correct |
52 ms |
680 KB |
Output is correct |
16 |
Correct |
93 ms |
700 KB |
Output is correct |
17 |
Correct |
99 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
959 ms |
692 KB |
Output is correct |
2 |
Correct |
714 ms |
688 KB |
Output is correct |
3 |
Correct |
707 ms |
656 KB |
Output is correct |
4 |
Correct |
4 ms |
732 KB |
Output is correct |
5 |
Correct |
3 ms |
732 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
596 ms |
656 KB |
Output is correct |
8 |
Correct |
983 ms |
656 KB |
Output is correct |
9 |
Correct |
708 ms |
688 KB |
Output is correct |
10 |
Correct |
714 ms |
688 KB |
Output is correct |
11 |
Correct |
7 ms |
736 KB |
Output is correct |
12 |
Correct |
7 ms |
732 KB |
Output is correct |
13 |
Correct |
5 ms |
728 KB |
Output is correct |
14 |
Correct |
4 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
529 ms |
656 KB |
Output is correct |
17 |
Correct |
697 ms |
692 KB |
Output is correct |
18 |
Correct |
628 ms |
656 KB |
Output is correct |
19 |
Correct |
585 ms |
656 KB |
Output is correct |
20 |
Correct |
584 ms |
656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
724 ms |
816 KB |
Output is correct |
2 |
Correct |
520 ms |
816 KB |
Output is correct |
3 |
Correct |
926 ms |
688 KB |
Output is correct |
4 |
Correct |
728 ms |
656 KB |
Output is correct |
5 |
Correct |
711 ms |
656 KB |
Output is correct |
6 |
Correct |
612 ms |
784 KB |
Output is correct |
7 |
Correct |
600 ms |
784 KB |
Output is correct |
8 |
Correct |
3 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
732 KB |
Output is correct |
11 |
Correct |
520 ms |
804 KB |
Output is correct |
12 |
Correct |
663 ms |
688 KB |
Output is correct |
13 |
Correct |
1101 ms |
656 KB |
Output is correct |
14 |
Correct |
691 ms |
656 KB |
Output is correct |
15 |
Correct |
815 ms |
656 KB |
Output is correct |
16 |
Correct |
528 ms |
692 KB |
Output is correct |
17 |
Correct |
736 ms |
700 KB |
Output is correct |
18 |
Correct |
527 ms |
1032 KB |
Output is correct |
19 |
Correct |
477 ms |
824 KB |
Output is correct |
20 |
Correct |
541 ms |
692 KB |
Output is correct |
21 |
Correct |
54 ms |
736 KB |
Output is correct |
22 |
Correct |
72 ms |
800 KB |
Output is correct |
23 |
Correct |
145 ms |
784 KB |
Output is correct |
24 |
Correct |
4 ms |
724 KB |
Output is correct |
25 |
Correct |
5 ms |
724 KB |
Output is correct |
26 |
Correct |
7 ms |
732 KB |
Output is correct |
27 |
Correct |
3 ms |
724 KB |
Output is correct |
28 |
Correct |
2 ms |
732 KB |
Output is correct |
29 |
Correct |
460 ms |
656 KB |
Output is correct |
30 |
Correct |
673 ms |
656 KB |
Output is correct |
31 |
Correct |
658 ms |
696 KB |
Output is correct |
32 |
Correct |
641 ms |
656 KB |
Output is correct |
33 |
Correct |
723 ms |
668 KB |
Output is correct |
34 |
Correct |
337 ms |
784 KB |
Output is correct |
35 |
Correct |
583 ms |
912 KB |
Output is correct |
36 |
Correct |
609 ms |
840 KB |
Output is correct |
37 |
Correct |
524 ms |
992 KB |
Output is correct |
38 |
Correct |
567 ms |
912 KB |
Output is correct |
39 |
Correct |
566 ms |
932 KB |
Output is correct |
40 |
Correct |
537 ms |
784 KB |
Output is correct |
41 |
Correct |
590 ms |
828 KB |
Output is correct |
42 |
Correct |
79 ms |
656 KB |
Output is correct |
43 |
Correct |
113 ms |
804 KB |
Output is correct |
44 |
Correct |
194 ms |
844 KB |
Output is correct |
45 |
Correct |
175 ms |
824 KB |
Output is correct |
46 |
Correct |
338 ms |
784 KB |
Output is correct |
47 |
Correct |
417 ms |
796 KB |
Output is correct |
48 |
Correct |
91 ms |
800 KB |
Output is correct |
49 |
Correct |
60 ms |
840 KB |
Output is correct |