#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
typedef long long int lld;
vector<int> nei[100000];
int L[100000];
int R[100000];
int cnt;
bool visited[100000];
bool parity[1000000];
void DFS(int node){
visited[node]=true;
L[node]=cnt;
cnt++;
trav(a,nei[node]){
if(!visited[a]){
parity[a]=1^parity[node];
DFS(a);
}
}
R[node]=cnt-1;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
rep(i,0,n)nei[i].clear();
rep(i,0,(int)u.size()){
nei[u[i]].push_back(v[i]);
nei[v[i]].push_back(u[i]);
}
cnt=0;
rep(i,0,n)visited[i]=false;
parity[0]=false;
DFS(0);
vector<pair<pair<int,int>,pair<int,int> > >V(n);
rep(i,0,n){
V[i]={{(parity[i] ? R[i] : L[i]),parity[i]},{-L[i],i}};
}
sort(V.begin(),V.end());
/*rep(i,0,n){
cout<<R[V[i].second.second]<<endl;
cout<<V[i].first.first<<" "<<V[i].first.second<<" "<<V[i].second.first<<" "<<V[i].second.second<<endl;
}*/
vector<int> answer(n);
rep(i,0,n)answer[V[i].second.second]=i;
//rep(i,0,n)cout<<answer[i]<<endl;
return answer;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c.size()==1)return c[0];
sort(c.begin(),c.end());
if(c[c.size()-1]<s){
//parity=R
int L=c[1];
int R=s;
if(t<L || R<t){
return c[0];
}
int best=-1;
trav(a,c){
if(a<=t)best=max(best,a);
}
return best;
}
//parity=L
reverse(c.begin(),c.end());
//trav(a,c)cout<<a<<endl;
int L=s;
int R=c[1];
if(t<L || R<t)return c[0];
//cout<<t<<" "<<L<<" "<<R<<endl;
int best=1000000;
trav(a,c){
if(t<=a)best=min(best,a);
}
return best;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
478 ms |
5488 KB |
Output is correct |
2 |
Correct |
534 ms |
5412 KB |
Output is correct |
3 |
Correct |
1060 ms |
5284 KB |
Output is correct |
4 |
Correct |
735 ms |
5292 KB |
Output is correct |
5 |
Correct |
570 ms |
5280 KB |
Output is correct |
6 |
Correct |
464 ms |
5400 KB |
Output is correct |
7 |
Correct |
498 ms |
5412 KB |
Output is correct |
8 |
Correct |
5 ms |
5376 KB |
Output is correct |
9 |
Correct |
6 ms |
5364 KB |
Output is correct |
10 |
Correct |
4 ms |
5364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
436 ms |
5280 KB |
Output is correct |
2 |
Correct |
518 ms |
5284 KB |
Output is correct |
3 |
Correct |
751 ms |
5280 KB |
Output is correct |
4 |
Correct |
680 ms |
5280 KB |
Output is correct |
5 |
Correct |
673 ms |
5284 KB |
Output is correct |
6 |
Correct |
412 ms |
5280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
625 ms |
5396 KB |
Output is correct |
2 |
Correct |
518 ms |
5412 KB |
Output is correct |
3 |
Correct |
982 ms |
5280 KB |
Output is correct |
4 |
Correct |
797 ms |
5296 KB |
Output is correct |
5 |
Correct |
596 ms |
5300 KB |
Output is correct |
6 |
Correct |
435 ms |
5408 KB |
Output is correct |
7 |
Correct |
467 ms |
5408 KB |
Output is correct |
8 |
Correct |
6 ms |
5360 KB |
Output is correct |
9 |
Correct |
6 ms |
5364 KB |
Output is correct |
10 |
Correct |
4 ms |
5364 KB |
Output is correct |
11 |
Correct |
640 ms |
5292 KB |
Output is correct |
12 |
Correct |
452 ms |
5500 KB |
Output is correct |
13 |
Correct |
436 ms |
5400 KB |
Output is correct |
14 |
Correct |
373 ms |
5292 KB |
Output is correct |
15 |
Correct |
68 ms |
5296 KB |
Output is correct |
16 |
Correct |
65 ms |
5332 KB |
Output is correct |
17 |
Correct |
95 ms |
5280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
851 ms |
5284 KB |
Output is correct |
2 |
Correct |
616 ms |
5300 KB |
Output is correct |
3 |
Correct |
580 ms |
5292 KB |
Output is correct |
4 |
Correct |
4 ms |
5364 KB |
Output is correct |
5 |
Correct |
6 ms |
5364 KB |
Output is correct |
6 |
Correct |
2 ms |
5364 KB |
Output is correct |
7 |
Correct |
655 ms |
5300 KB |
Output is correct |
8 |
Correct |
751 ms |
5292 KB |
Output is correct |
9 |
Correct |
632 ms |
5284 KB |
Output is correct |
10 |
Correct |
593 ms |
5292 KB |
Output is correct |
11 |
Correct |
6 ms |
5372 KB |
Output is correct |
12 |
Correct |
7 ms |
5372 KB |
Output is correct |
13 |
Correct |
6 ms |
5372 KB |
Output is correct |
14 |
Correct |
6 ms |
5372 KB |
Output is correct |
15 |
Correct |
4 ms |
5372 KB |
Output is correct |
16 |
Correct |
467 ms |
5288 KB |
Output is correct |
17 |
Correct |
463 ms |
5280 KB |
Output is correct |
18 |
Correct |
523 ms |
5344 KB |
Output is correct |
19 |
Correct |
446 ms |
5284 KB |
Output is correct |
20 |
Correct |
524 ms |
5296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
542 ms |
5500 KB |
Output is correct |
2 |
Correct |
517 ms |
5420 KB |
Output is correct |
3 |
Correct |
891 ms |
5280 KB |
Output is correct |
4 |
Correct |
607 ms |
5292 KB |
Output is correct |
5 |
Correct |
636 ms |
5284 KB |
Output is correct |
6 |
Correct |
449 ms |
5420 KB |
Output is correct |
7 |
Correct |
451 ms |
5352 KB |
Output is correct |
8 |
Correct |
3 ms |
5364 KB |
Output is correct |
9 |
Correct |
6 ms |
5364 KB |
Output is correct |
10 |
Correct |
4 ms |
5364 KB |
Output is correct |
11 |
Correct |
407 ms |
5396 KB |
Output is correct |
12 |
Correct |
520 ms |
5280 KB |
Output is correct |
13 |
Correct |
799 ms |
5280 KB |
Output is correct |
14 |
Correct |
674 ms |
5280 KB |
Output is correct |
15 |
Correct |
503 ms |
5296 KB |
Output is correct |
16 |
Correct |
489 ms |
5280 KB |
Output is correct |
17 |
Correct |
540 ms |
5288 KB |
Output is correct |
18 |
Correct |
381 ms |
5416 KB |
Output is correct |
19 |
Correct |
436 ms |
5412 KB |
Output is correct |
20 |
Correct |
380 ms |
5296 KB |
Output is correct |
21 |
Correct |
45 ms |
5304 KB |
Output is correct |
22 |
Correct |
63 ms |
5348 KB |
Output is correct |
23 |
Correct |
103 ms |
5412 KB |
Output is correct |
24 |
Correct |
6 ms |
5376 KB |
Output is correct |
25 |
Correct |
6 ms |
5364 KB |
Output is correct |
26 |
Correct |
6 ms |
5372 KB |
Output is correct |
27 |
Correct |
5 ms |
5360 KB |
Output is correct |
28 |
Correct |
4 ms |
5368 KB |
Output is correct |
29 |
Correct |
520 ms |
5296 KB |
Output is correct |
30 |
Correct |
501 ms |
5212 KB |
Output is correct |
31 |
Correct |
469 ms |
5284 KB |
Output is correct |
32 |
Correct |
580 ms |
5408 KB |
Output is correct |
33 |
Correct |
500 ms |
5284 KB |
Output is correct |
34 |
Correct |
289 ms |
5408 KB |
Output is correct |
35 |
Correct |
429 ms |
5416 KB |
Output is correct |
36 |
Correct |
427 ms |
5412 KB |
Output is correct |
37 |
Correct |
463 ms |
5532 KB |
Output is correct |
38 |
Correct |
454 ms |
5432 KB |
Output is correct |
39 |
Correct |
438 ms |
5428 KB |
Output is correct |
40 |
Correct |
402 ms |
5416 KB |
Output is correct |
41 |
Correct |
430 ms |
5424 KB |
Output is correct |
42 |
Correct |
61 ms |
5280 KB |
Output is correct |
43 |
Correct |
112 ms |
5360 KB |
Output is correct |
44 |
Correct |
141 ms |
5412 KB |
Output is correct |
45 |
Correct |
160 ms |
5292 KB |
Output is correct |
46 |
Correct |
301 ms |
5296 KB |
Output is correct |
47 |
Correct |
328 ms |
5280 KB |
Output is correct |
48 |
Correct |
44 ms |
5492 KB |
Output is correct |
49 |
Correct |
66 ms |
5476 KB |
Output is correct |