#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
const int nax = 1001;
vi rep;
int cureul = -1;
vi adj[nax];
int in[nax], out[nax];
void dfs(int x, int d = 0, int p = -1)
{
in[x] = cureul++;
for(auto e: adj[x])
if(e != p)
dfs(e, d + 1, x);
out[x] = cureul++;
if(d & 1)
rep[x] = out[x];
else
rep[x] = in[x];
}
vi label(int n, int k, vi u, vi v)
{
for(int i = 0 ; i < n; i++)
adj[i].clear();
cureul = 0;
rep.assign(n , 0);
for(int i= 0; i < n - 1; i ++)
{
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
dfs(0);
vpi vec;
for(int i = 0; i < n; i++)
vec.pb({rep[i], i});
sort(all(vec));
for(int i = 0 ; i < n ;i++)
rep[vec[i].ss] = i;
return rep;
}
int find_next_station(int s, int t, vi c)
{
sort(all(c));
int sz = c.size();
bool ev = s < c[0];
int ini, outi;
if(ev)
{
ini = s;
if(s == 0)
outi = 1999;
else if(sz == 1)
outi = ini + 1;
else
outi = c[sz - 2] + 1;
if(t >= ini && t <= outi)
{
for(auto e: c)
if(e >= t)
return e;
}
else
{
return c[sz - 1];
}
}
else
{
outi = s;
if(sz == 1)
ini = outi;
else
ini = c[1] - 1;
if(t >= ini && t <= outi)
{
reverse(all(c));
for(auto e: c)
if(e <= t)
return e;
}
else
{
return c[0];
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, vi)':
stations.cpp:106:5: warning: control reaches end of non-void function [-Wreturn-type]
106 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
585 ms |
672 KB |
Output is correct |
2 |
Correct |
454 ms |
652 KB |
Output is correct |
3 |
Correct |
860 ms |
536 KB |
Output is correct |
4 |
Correct |
696 ms |
416 KB |
Output is correct |
5 |
Correct |
652 ms |
416 KB |
Output is correct |
6 |
Correct |
431 ms |
664 KB |
Output is correct |
7 |
Correct |
439 ms |
536 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
6 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
510 ms |
540 KB |
Output is correct |
2 |
Correct |
510 ms |
544 KB |
Output is correct |
3 |
Correct |
1025 ms |
528 KB |
Output is correct |
4 |
Correct |
563 ms |
416 KB |
Output is correct |
5 |
Correct |
581 ms |
560 KB |
Output is correct |
6 |
Correct |
454 ms |
536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
558 ms |
676 KB |
Output is correct |
2 |
Correct |
411 ms |
676 KB |
Output is correct |
3 |
Correct |
695 ms |
420 KB |
Output is correct |
4 |
Correct |
664 ms |
532 KB |
Output is correct |
5 |
Correct |
558 ms |
532 KB |
Output is correct |
6 |
Correct |
437 ms |
672 KB |
Output is correct |
7 |
Correct |
433 ms |
676 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
4 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
488 KB |
Output is correct |
11 |
Correct |
557 ms |
532 KB |
Output is correct |
12 |
Correct |
467 ms |
756 KB |
Output is correct |
13 |
Correct |
451 ms |
784 KB |
Output is correct |
14 |
Correct |
418 ms |
548 KB |
Output is correct |
15 |
Correct |
54 ms |
544 KB |
Output is correct |
16 |
Correct |
68 ms |
592 KB |
Output is correct |
17 |
Correct |
124 ms |
672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
889 ms |
416 KB |
Output is correct |
2 |
Correct |
685 ms |
540 KB |
Output is correct |
3 |
Correct |
501 ms |
528 KB |
Output is correct |
4 |
Correct |
2 ms |
620 KB |
Output is correct |
5 |
Correct |
4 ms |
500 KB |
Output is correct |
6 |
Correct |
0 ms |
500 KB |
Output is correct |
7 |
Correct |
575 ms |
532 KB |
Output is correct |
8 |
Correct |
899 ms |
536 KB |
Output is correct |
9 |
Correct |
651 ms |
420 KB |
Output is correct |
10 |
Correct |
524 ms |
536 KB |
Output is correct |
11 |
Correct |
4 ms |
628 KB |
Output is correct |
12 |
Correct |
5 ms |
500 KB |
Output is correct |
13 |
Correct |
4 ms |
500 KB |
Output is correct |
14 |
Correct |
4 ms |
500 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
462 ms |
416 KB |
Output is correct |
17 |
Correct |
538 ms |
416 KB |
Output is correct |
18 |
Correct |
528 ms |
420 KB |
Output is correct |
19 |
Correct |
481 ms |
532 KB |
Output is correct |
20 |
Correct |
510 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
548 ms |
676 KB |
Output is correct |
2 |
Correct |
455 ms |
660 KB |
Output is correct |
3 |
Correct |
889 ms |
420 KB |
Output is correct |
4 |
Correct |
591 ms |
532 KB |
Output is correct |
5 |
Correct |
645 ms |
528 KB |
Output is correct |
6 |
Correct |
403 ms |
664 KB |
Output is correct |
7 |
Correct |
420 ms |
532 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
2 ms |
500 KB |
Output is correct |
10 |
Correct |
0 ms |
488 KB |
Output is correct |
11 |
Correct |
388 ms |
544 KB |
Output is correct |
12 |
Correct |
455 ms |
544 KB |
Output is correct |
13 |
Correct |
781 ms |
540 KB |
Output is correct |
14 |
Correct |
580 ms |
536 KB |
Output is correct |
15 |
Correct |
490 ms |
548 KB |
Output is correct |
16 |
Correct |
405 ms |
536 KB |
Output is correct |
17 |
Correct |
525 ms |
536 KB |
Output is correct |
18 |
Correct |
552 ms |
652 KB |
Output is correct |
19 |
Correct |
497 ms |
772 KB |
Output is correct |
20 |
Correct |
457 ms |
544 KB |
Output is correct |
21 |
Correct |
54 ms |
620 KB |
Output is correct |
22 |
Correct |
58 ms |
620 KB |
Output is correct |
23 |
Correct |
116 ms |
700 KB |
Output is correct |
24 |
Correct |
6 ms |
624 KB |
Output is correct |
25 |
Correct |
6 ms |
500 KB |
Output is correct |
26 |
Correct |
4 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
0 ms |
628 KB |
Output is correct |
29 |
Correct |
449 ms |
420 KB |
Output is correct |
30 |
Correct |
437 ms |
548 KB |
Output is correct |
31 |
Correct |
428 ms |
528 KB |
Output is correct |
32 |
Correct |
461 ms |
536 KB |
Output is correct |
33 |
Correct |
424 ms |
416 KB |
Output is correct |
34 |
Correct |
268 ms |
660 KB |
Output is correct |
35 |
Correct |
373 ms |
776 KB |
Output is correct |
36 |
Correct |
394 ms |
768 KB |
Output is correct |
37 |
Correct |
398 ms |
640 KB |
Output is correct |
38 |
Correct |
397 ms |
640 KB |
Output is correct |
39 |
Correct |
507 ms |
652 KB |
Output is correct |
40 |
Correct |
454 ms |
640 KB |
Output is correct |
41 |
Correct |
511 ms |
540 KB |
Output is correct |
42 |
Correct |
68 ms |
620 KB |
Output is correct |
43 |
Correct |
114 ms |
736 KB |
Output is correct |
44 |
Correct |
137 ms |
548 KB |
Output is correct |
45 |
Correct |
159 ms |
548 KB |
Output is correct |
46 |
Correct |
337 ms |
528 KB |
Output is correct |
47 |
Correct |
331 ms |
544 KB |
Output is correct |
48 |
Correct |
64 ms |
672 KB |
Output is correct |
49 |
Correct |
61 ms |
700 KB |
Output is correct |