#include "stations.h"
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i = (a); i <= (b); i++)
#define pb push_back
using namespace std;
vector<int> graf[1001];
int pre[1001];
int akt_pre = 0;
void dfs(int v, int pop, int dist)
{
if(dist % 2 == 0) pre[v] = akt_pre;
akt_pre++;
for(auto& it: graf[v])
{
if(it != pop) dfs(it,v,dist+1);
}
if(dist % 2 == 1) pre[v] = akt_pre;
akt_pre++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
rep2(i,0,n-1) graf[i].clear();
rep2(i,0,n-2)
{
graf[u[i]].pb(v[i]);
graf[v[i]].pb(u[i]);
}
akt_pre = 0;
dfs(0,0,0);
vector<pair<int,int>> labels;
rep2(i,0,n-1) labels.pb({pre[i],i});
sort(labels.begin(),labels.end());
vector<int> ans(n);
int akt_poz = 0;
for(auto& it: labels)
{
ans[it.second] = akt_poz;
akt_poz++;
}
//for(auto it: ans)
//{
// cout << it << " ";
//}
//cout << " ans\n";
return ans;
}
int find_next_station(int s, int t, vector<int> post)
{
// post
int n = (int)post.size();
vector<int> nums(n);
rep2(i,0,n-1) nums[i] = post[i];
vector<int> pre(n);
int root;
if(s > post[0])
{
root = 0;
swap(pre,post);
int pop = s;
for(int i = n-1; i >= 1; i--)
{
post[i] = pop-1;
pop = pre[i];
}
}
else //pre
{
root = n-1;
int pop = s;
for(int i = 0; i < n-1; i++)
{
pre[i] = pop+1;
pop = post[i];
}
}
for(int i = 0; i < n; i++)
{
if(i == root) continue;
//cout << nums[i] << " " << pre[i] << " " << post[i] << " pre/post\n";
if(t >= pre[i] && t <= post[i])
{
//cout << nums[i] << " return\n";
return nums[i];
}
}
//cout << nums[root] << " " << root << " return\n";
return nums[root];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
352 ms |
944 KB |
Output is correct |
2 |
Correct |
316 ms |
940 KB |
Output is correct |
3 |
Correct |
645 ms |
684 KB |
Output is correct |
4 |
Correct |
428 ms |
684 KB |
Output is correct |
5 |
Correct |
436 ms |
684 KB |
Output is correct |
6 |
Correct |
323 ms |
936 KB |
Output is correct |
7 |
Correct |
302 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
772 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
304 ms |
684 KB |
Output is correct |
2 |
Correct |
367 ms |
684 KB |
Output is correct |
3 |
Correct |
613 ms |
684 KB |
Output is correct |
4 |
Correct |
444 ms |
684 KB |
Output is correct |
5 |
Correct |
424 ms |
684 KB |
Output is correct |
6 |
Correct |
310 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
344 ms |
940 KB |
Output is correct |
2 |
Correct |
309 ms |
940 KB |
Output is correct |
3 |
Correct |
581 ms |
684 KB |
Output is correct |
4 |
Correct |
495 ms |
684 KB |
Output is correct |
5 |
Correct |
401 ms |
684 KB |
Output is correct |
6 |
Correct |
302 ms |
940 KB |
Output is correct |
7 |
Correct |
291 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
417 ms |
684 KB |
Output is correct |
12 |
Correct |
324 ms |
1044 KB |
Output is correct |
13 |
Correct |
324 ms |
1188 KB |
Output is correct |
14 |
Correct |
296 ms |
684 KB |
Output is correct |
15 |
Correct |
42 ms |
768 KB |
Output is correct |
16 |
Correct |
30 ms |
768 KB |
Output is correct |
17 |
Correct |
61 ms |
1016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
614 ms |
684 KB |
Output is correct |
2 |
Correct |
470 ms |
684 KB |
Output is correct |
3 |
Correct |
379 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
776 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
0 ms |
780 KB |
Output is correct |
7 |
Correct |
394 ms |
712 KB |
Output is correct |
8 |
Correct |
628 ms |
684 KB |
Output is correct |
9 |
Correct |
442 ms |
684 KB |
Output is correct |
10 |
Correct |
433 ms |
684 KB |
Output is correct |
11 |
Correct |
2 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
768 KB |
Output is correct |
13 |
Correct |
2 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
0 ms |
776 KB |
Output is correct |
16 |
Correct |
310 ms |
684 KB |
Output is correct |
17 |
Correct |
316 ms |
684 KB |
Output is correct |
18 |
Correct |
353 ms |
684 KB |
Output is correct |
19 |
Correct |
349 ms |
684 KB |
Output is correct |
20 |
Correct |
338 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
350 ms |
940 KB |
Output is correct |
2 |
Correct |
306 ms |
684 KB |
Output is correct |
3 |
Correct |
667 ms |
684 KB |
Output is correct |
4 |
Correct |
447 ms |
684 KB |
Output is correct |
5 |
Correct |
395 ms |
684 KB |
Output is correct |
6 |
Correct |
315 ms |
940 KB |
Output is correct |
7 |
Correct |
312 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
288 ms |
688 KB |
Output is correct |
12 |
Correct |
375 ms |
684 KB |
Output is correct |
13 |
Correct |
640 ms |
684 KB |
Output is correct |
14 |
Correct |
471 ms |
684 KB |
Output is correct |
15 |
Correct |
453 ms |
684 KB |
Output is correct |
16 |
Correct |
313 ms |
684 KB |
Output is correct |
17 |
Correct |
436 ms |
940 KB |
Output is correct |
18 |
Correct |
315 ms |
808 KB |
Output is correct |
19 |
Correct |
323 ms |
1068 KB |
Output is correct |
20 |
Correct |
292 ms |
684 KB |
Output is correct |
21 |
Correct |
30 ms |
764 KB |
Output is correct |
22 |
Correct |
39 ms |
764 KB |
Output is correct |
23 |
Correct |
61 ms |
744 KB |
Output is correct |
24 |
Correct |
3 ms |
776 KB |
Output is correct |
25 |
Correct |
2 ms |
768 KB |
Output is correct |
26 |
Correct |
3 ms |
764 KB |
Output is correct |
27 |
Correct |
1 ms |
768 KB |
Output is correct |
28 |
Correct |
0 ms |
768 KB |
Output is correct |
29 |
Correct |
387 ms |
684 KB |
Output is correct |
30 |
Correct |
359 ms |
736 KB |
Output is correct |
31 |
Correct |
384 ms |
684 KB |
Output is correct |
32 |
Correct |
356 ms |
688 KB |
Output is correct |
33 |
Correct |
359 ms |
684 KB |
Output is correct |
34 |
Correct |
207 ms |
684 KB |
Output is correct |
35 |
Correct |
297 ms |
1072 KB |
Output is correct |
36 |
Correct |
310 ms |
1044 KB |
Output is correct |
37 |
Correct |
303 ms |
932 KB |
Output is correct |
38 |
Correct |
290 ms |
800 KB |
Output is correct |
39 |
Correct |
315 ms |
804 KB |
Output is correct |
40 |
Correct |
312 ms |
1060 KB |
Output is correct |
41 |
Correct |
331 ms |
796 KB |
Output is correct |
42 |
Correct |
37 ms |
744 KB |
Output is correct |
43 |
Correct |
79 ms |
768 KB |
Output is correct |
44 |
Correct |
80 ms |
688 KB |
Output is correct |
45 |
Correct |
105 ms |
992 KB |
Output is correct |
46 |
Correct |
183 ms |
684 KB |
Output is correct |
47 |
Correct |
185 ms |
684 KB |
Output is correct |
48 |
Correct |
36 ms |
744 KB |
Output is correct |
49 |
Correct |
35 ms |
944 KB |
Output is correct |