#include "stations.h"
#include <bits/stdc++.h>
#define lp(i,a,b) for(int i = a; i < b; i++)
#define debug //printf
#define ff first
#define ss second
#define mk make_pair
#define ll long long
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x.size())
const int MAXN = 1010 ;
using namespace std ;
int tin[MAXN] , tout[MAXN] ;
vector<int> adj[MAXN] ;
int currTime = -1 ;
void dfs(int x, int father)
{
tin[x] = tout[x] = ++currTime ;
for(auto e :adj[x])
{
if(e == father) continue ;
dfs(e,x) ;
tout[x] = ++currTime ;
}
if( (tin[x]&1) != (tout[x]&1) ) tout[x] = ++currTime ;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
for(int i = 0 ; i < n ; i++ ) adj[i].clear() ;
currTime = -1 ;
for(int i = 0 ; i <n-1 ; i++ )
{
adj[ u[i] ].push_back(v[i]) ;
adj[v[i]].push_back(u[i]) ;
}
dfs(0,-1) ;
vector<int> labels(n) ;
map<int,int> mp ;
for(int i = 0 ; i < n ; i++ )
{
if(tin[i]&1) labels[i] = tin[i] ;
else labels[i] = tout[i] ;
mp[labels[i]] = 0 ;
}
int Key = 0 ;
for(auto &e : mp ) e.ss = Key++ ;
lp(i,0,n) labels[i] = mp[labels[i]] ;
return labels ;
}
int find_next_station(int s, int t, std::vector<int> c) {
for(auto e: c )
if(e == t) return t ;
bool sOdd = ( s < c[0] ) ;
if( !sOdd )
{
//ou seja, tenho os tin's
if(t > s ) return c[0] ;
for(int i = sz(c) - 1 ; i>= 0 ; i-- )
if( c[i] < t ) return c[i] ;
return c[0] ;
}
else
{
//tenho os tout's
if( t < s ) return c[ sz(c)-1 ] ;
for(int i = 0 ; i < sz(c) ; i++ )
if( c[i] > t ) return c[i] ;
return c[ sz(c)-1 ] ;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
529 ms |
1024 KB |
Output is correct |
2 |
Correct |
462 ms |
1280 KB |
Output is correct |
3 |
Correct |
865 ms |
1008 KB |
Output is correct |
4 |
Correct |
679 ms |
768 KB |
Output is correct |
5 |
Correct |
600 ms |
868 KB |
Output is correct |
6 |
Correct |
445 ms |
1024 KB |
Output is correct |
7 |
Correct |
469 ms |
1008 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
475 ms |
792 KB |
Output is correct |
2 |
Correct |
550 ms |
768 KB |
Output is correct |
3 |
Correct |
922 ms |
872 KB |
Output is correct |
4 |
Correct |
697 ms |
868 KB |
Output is correct |
5 |
Correct |
589 ms |
1024 KB |
Output is correct |
6 |
Correct |
440 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
574 ms |
1024 KB |
Output is correct |
2 |
Correct |
476 ms |
1024 KB |
Output is correct |
3 |
Correct |
929 ms |
876 KB |
Output is correct |
4 |
Correct |
730 ms |
868 KB |
Output is correct |
5 |
Correct |
702 ms |
768 KB |
Output is correct |
6 |
Correct |
542 ms |
1008 KB |
Output is correct |
7 |
Correct |
456 ms |
1008 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
868 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
655 ms |
864 KB |
Output is correct |
12 |
Correct |
502 ms |
1024 KB |
Output is correct |
13 |
Correct |
497 ms |
1024 KB |
Output is correct |
14 |
Correct |
522 ms |
780 KB |
Output is correct |
15 |
Correct |
54 ms |
860 KB |
Output is correct |
16 |
Correct |
69 ms |
940 KB |
Output is correct |
17 |
Correct |
129 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
930 ms |
868 KB |
Output is correct |
2 |
Correct |
750 ms |
872 KB |
Output is correct |
3 |
Correct |
692 ms |
780 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
868 KB |
Output is correct |
6 |
Correct |
2 ms |
768 KB |
Output is correct |
7 |
Correct |
714 ms |
768 KB |
Output is correct |
8 |
Correct |
960 ms |
872 KB |
Output is correct |
9 |
Correct |
801 ms |
872 KB |
Output is correct |
10 |
Correct |
687 ms |
768 KB |
Output is correct |
11 |
Correct |
7 ms |
768 KB |
Output is correct |
12 |
Correct |
4 ms |
768 KB |
Output is correct |
13 |
Correct |
5 ms |
868 KB |
Output is correct |
14 |
Correct |
4 ms |
872 KB |
Output is correct |
15 |
Correct |
1 ms |
1000 KB |
Output is correct |
16 |
Correct |
508 ms |
876 KB |
Output is correct |
17 |
Correct |
626 ms |
768 KB |
Output is correct |
18 |
Correct |
609 ms |
872 KB |
Output is correct |
19 |
Correct |
531 ms |
868 KB |
Output is correct |
20 |
Correct |
654 ms |
1040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
621 ms |
1320 KB |
Output is correct |
2 |
Correct |
512 ms |
1024 KB |
Output is correct |
3 |
Correct |
915 ms |
768 KB |
Output is correct |
4 |
Correct |
669 ms |
864 KB |
Output is correct |
5 |
Correct |
594 ms |
1024 KB |
Output is correct |
6 |
Correct |
458 ms |
1024 KB |
Output is correct |
7 |
Correct |
477 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
6 ms |
996 KB |
Output is correct |
10 |
Correct |
2 ms |
868 KB |
Output is correct |
11 |
Correct |
592 ms |
768 KB |
Output is correct |
12 |
Correct |
586 ms |
772 KB |
Output is correct |
13 |
Correct |
1003 ms |
868 KB |
Output is correct |
14 |
Correct |
685 ms |
768 KB |
Output is correct |
15 |
Correct |
637 ms |
868 KB |
Output is correct |
16 |
Correct |
573 ms |
776 KB |
Output is correct |
17 |
Correct |
698 ms |
768 KB |
Output is correct |
18 |
Correct |
566 ms |
1120 KB |
Output is correct |
19 |
Correct |
529 ms |
1024 KB |
Output is correct |
20 |
Correct |
471 ms |
776 KB |
Output is correct |
21 |
Correct |
53 ms |
852 KB |
Output is correct |
22 |
Correct |
78 ms |
768 KB |
Output is correct |
23 |
Correct |
111 ms |
768 KB |
Output is correct |
24 |
Correct |
5 ms |
872 KB |
Output is correct |
25 |
Correct |
6 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
872 KB |
Output is correct |
27 |
Correct |
4 ms |
768 KB |
Output is correct |
28 |
Correct |
2 ms |
768 KB |
Output is correct |
29 |
Correct |
563 ms |
864 KB |
Output is correct |
30 |
Correct |
550 ms |
768 KB |
Output is correct |
31 |
Correct |
497 ms |
768 KB |
Output is correct |
32 |
Correct |
551 ms |
1048 KB |
Output is correct |
33 |
Correct |
534 ms |
768 KB |
Output is correct |
34 |
Correct |
363 ms |
1024 KB |
Output is correct |
35 |
Correct |
503 ms |
1024 KB |
Output is correct |
36 |
Correct |
551 ms |
1024 KB |
Output is correct |
37 |
Correct |
454 ms |
1016 KB |
Output is correct |
38 |
Correct |
508 ms |
1280 KB |
Output is correct |
39 |
Correct |
501 ms |
1024 KB |
Output is correct |
40 |
Correct |
437 ms |
1008 KB |
Output is correct |
41 |
Correct |
501 ms |
1112 KB |
Output is correct |
42 |
Correct |
63 ms |
920 KB |
Output is correct |
43 |
Correct |
118 ms |
832 KB |
Output is correct |
44 |
Correct |
158 ms |
1024 KB |
Output is correct |
45 |
Correct |
163 ms |
1024 KB |
Output is correct |
46 |
Correct |
322 ms |
788 KB |
Output is correct |
47 |
Correct |
338 ms |
1024 KB |
Output is correct |
48 |
Correct |
67 ms |
1024 KB |
Output is correct |
49 |
Correct |
64 ms |
1024 KB |
Output is correct |