#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=1010;
int n,tin[mxn],tout[mxn],tmr,color[mxn];
vector<int>vt[mxn];
void dfs(int u,int p,int dep){
tin[u]=tmr++;
for(int v:vt[u]){
if(v!=p){
dfs(v,u,dep+1);
}
}
tout[u]=tmr++;
if(dep%2==0){
color[u]=tin[u]/2;
}
else{
color[u]=tout[u]/2;
}
}
vector<int> label(int N, int k, vector<int> u, vector<int> v) {
n=N;
for(int i=1;i<=n;i++){
vt[i].clear();
color[i]=0;
tin[i]=0;
tout[i]=0;
}
tmr=0;
for(int i=0;i<u.size();i++){
vt[u[i]+1].pb(v[i]+1);
vt[v[i]+1].pb(u[i]+1);
}
dfs(1,-1,0);
vector<int> labels(n);
for (int i = 0; i < n; i++) {
labels[i] = color[i+1];
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c[0]>s){
if(t<s) return c.back();
auto it=lower_bound(all(c),t);
if(it==c.end()) it--;
return *it;
}
else{
if(t>s) return c[0];
auto it=upper_bound(all(c),t);
if(it!=c.begin()) it--;
return *it;
}
}
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=0;i<u.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
470 ms |
648 KB |
Output is correct |
2 |
Correct |
365 ms |
656 KB |
Output is correct |
3 |
Correct |
711 ms |
528 KB |
Output is correct |
4 |
Correct |
596 ms |
524 KB |
Output is correct |
5 |
Correct |
535 ms |
524 KB |
Output is correct |
6 |
Correct |
309 ms |
652 KB |
Output is correct |
7 |
Correct |
431 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
405 ms |
520 KB |
Output is correct |
2 |
Correct |
509 ms |
524 KB |
Output is correct |
3 |
Correct |
769 ms |
548 KB |
Output is correct |
4 |
Correct |
482 ms |
528 KB |
Output is correct |
5 |
Correct |
541 ms |
416 KB |
Output is correct |
6 |
Correct |
334 ms |
524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
446 ms |
672 KB |
Output is correct |
2 |
Correct |
322 ms |
656 KB |
Output is correct |
3 |
Correct |
865 ms |
516 KB |
Output is correct |
4 |
Correct |
597 ms |
416 KB |
Output is correct |
5 |
Correct |
415 ms |
532 KB |
Output is correct |
6 |
Correct |
264 ms |
660 KB |
Output is correct |
7 |
Correct |
342 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
0 ms |
620 KB |
Output is correct |
11 |
Correct |
403 ms |
552 KB |
Output is correct |
12 |
Correct |
426 ms |
648 KB |
Output is correct |
13 |
Correct |
317 ms |
772 KB |
Output is correct |
14 |
Correct |
327 ms |
536 KB |
Output is correct |
15 |
Correct |
45 ms |
628 KB |
Output is correct |
16 |
Correct |
57 ms |
548 KB |
Output is correct |
17 |
Correct |
82 ms |
672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
696 ms |
528 KB |
Output is correct |
2 |
Correct |
618 ms |
416 KB |
Output is correct |
3 |
Correct |
444 ms |
544 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
3 ms |
628 KB |
Output is correct |
6 |
Correct |
0 ms |
620 KB |
Output is correct |
7 |
Correct |
509 ms |
528 KB |
Output is correct |
8 |
Correct |
678 ms |
524 KB |
Output is correct |
9 |
Correct |
440 ms |
528 KB |
Output is correct |
10 |
Correct |
512 ms |
528 KB |
Output is correct |
11 |
Correct |
2 ms |
620 KB |
Output is correct |
12 |
Correct |
3 ms |
620 KB |
Output is correct |
13 |
Correct |
3 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
624 KB |
Output is correct |
15 |
Correct |
0 ms |
628 KB |
Output is correct |
16 |
Correct |
404 ms |
420 KB |
Output is correct |
17 |
Correct |
410 ms |
508 KB |
Output is correct |
18 |
Correct |
441 ms |
532 KB |
Output is correct |
19 |
Correct |
494 ms |
668 KB |
Output is correct |
20 |
Correct |
446 ms |
556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
422 ms |
648 KB |
Output is correct |
2 |
Correct |
323 ms |
728 KB |
Output is correct |
3 |
Correct |
694 ms |
660 KB |
Output is correct |
4 |
Correct |
593 ms |
548 KB |
Output is correct |
5 |
Correct |
435 ms |
544 KB |
Output is correct |
6 |
Correct |
341 ms |
548 KB |
Output is correct |
7 |
Correct |
283 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
628 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
620 KB |
Output is correct |
11 |
Correct |
328 ms |
536 KB |
Output is correct |
12 |
Correct |
479 ms |
580 KB |
Output is correct |
13 |
Correct |
659 ms |
548 KB |
Output is correct |
14 |
Correct |
575 ms |
420 KB |
Output is correct |
15 |
Correct |
520 ms |
528 KB |
Output is correct |
16 |
Correct |
366 ms |
528 KB |
Output is correct |
17 |
Correct |
526 ms |
676 KB |
Output is correct |
18 |
Correct |
292 ms |
632 KB |
Output is correct |
19 |
Correct |
273 ms |
716 KB |
Output is correct |
20 |
Correct |
363 ms |
592 KB |
Output is correct |
21 |
Correct |
44 ms |
528 KB |
Output is correct |
22 |
Correct |
62 ms |
648 KB |
Output is correct |
23 |
Correct |
66 ms |
548 KB |
Output is correct |
24 |
Correct |
6 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
500 KB |
Output is correct |
26 |
Correct |
2 ms |
616 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
454 ms |
524 KB |
Output is correct |
30 |
Correct |
420 ms |
536 KB |
Output is correct |
31 |
Correct |
447 ms |
544 KB |
Output is correct |
32 |
Correct |
350 ms |
544 KB |
Output is correct |
33 |
Correct |
338 ms |
524 KB |
Output is correct |
34 |
Correct |
202 ms |
660 KB |
Output is correct |
35 |
Correct |
377 ms |
908 KB |
Output is correct |
36 |
Correct |
353 ms |
664 KB |
Output is correct |
37 |
Correct |
412 ms |
652 KB |
Output is correct |
38 |
Correct |
341 ms |
636 KB |
Output is correct |
39 |
Correct |
338 ms |
660 KB |
Output is correct |
40 |
Correct |
336 ms |
660 KB |
Output is correct |
41 |
Correct |
376 ms |
644 KB |
Output is correct |
42 |
Correct |
49 ms |
764 KB |
Output is correct |
43 |
Correct |
108 ms |
616 KB |
Output is correct |
44 |
Correct |
73 ms |
676 KB |
Output is correct |
45 |
Correct |
142 ms |
544 KB |
Output is correct |
46 |
Correct |
304 ms |
536 KB |
Output is correct |
47 |
Correct |
264 ms |
528 KB |
Output is correct |
48 |
Correct |
50 ms |
728 KB |
Output is correct |
49 |
Correct |
42 ms |
800 KB |
Output is correct |