#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define pb push_back
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define x first
#define y second
//#define int long long
using namespace std;
const int N = 1001, INDEFINI = -1;
const pii TOUT = {-1, 1e6};
int deb[N], fin[N];
int profondeur[N];
int temps = 0;
bool vu[N];
vector<int> voisins[N];
void dfs(int noeud, int etage){
vu[noeud] = true;
deb[noeud] = (temps++)/2;
profondeur[noeud] = etage;
for (int voisin : voisins[noeud]){
if (vu[voisin]) continue;
dfs(voisin, etage + 1);
}
fin[noeud] = (temps++)/2;
}
vector<int> label(int nNoeuds, int labelMax, vector<int> u, vector<int> v) {
temps = 0;
for (int noeud = 0; noeud < nNoeuds; ++noeud){
deb[noeud] = fin[noeud] = INDEFINI;
vu[noeud] = false;
voisins[noeud] = {};
}
for (int i = 0; i < nNoeuds - 1; ++i){
voisins[u[i]].pb(v[i]);
voisins[v[i]].pb(u[i]);
}
dfs(0, 0);
vector<int> labels(nNoeuds);
for (int i = 0; i < nNoeuds; ++i){
if (profondeur[i]%2 == 0)
labels[i] = deb[i];
else
labels[i] = fin[i];
}
return labels;
}
int find_next_station(int source, int dest, vector<int> voisins) {
if (sz(voisins) == 1)
return voisins[0];
vector<pii> inters;
if (voisins[0] < source){
//on est une fin
inters.pb(TOUT);
for (int i = 1; i < sz(voisins) - 1; ++i)
inters.pb({voisins[i], voisins[i + 1] - 1});
inters.pb({voisins.back(), source - 1});
}
else {
//on est un debut
inters.pb({source + 1, voisins[0]});
for (int i = 1; i < sz(voisins) - 1; ++i)
inters.pb({voisins[i - 1] + 1, voisins[i]});
inters.pb(TOUT);
}
int iPere = -1;
for (int i = 0; i < sz(voisins); ++i){
if (inters[i].x <= source && source <= inters[i].y){
iPere = i;
continue; //si on est sur le pere
}
if (inters[i].x <= dest && dest <= inters[i].y)
return voisins[i];
}
return voisins[iPere];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
519 ms |
532 KB |
Output is correct |
2 |
Correct |
418 ms |
556 KB |
Output is correct |
3 |
Correct |
803 ms |
532 KB |
Output is correct |
4 |
Correct |
617 ms |
548 KB |
Output is correct |
5 |
Correct |
516 ms |
416 KB |
Output is correct |
6 |
Correct |
456 ms |
536 KB |
Output is correct |
7 |
Correct |
440 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
4 ms |
628 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
468 ms |
528 KB |
Output is correct |
2 |
Correct |
497 ms |
548 KB |
Output is correct |
3 |
Correct |
742 ms |
528 KB |
Output is correct |
4 |
Correct |
624 ms |
532 KB |
Output is correct |
5 |
Correct |
518 ms |
532 KB |
Output is correct |
6 |
Correct |
395 ms |
548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
505 ms |
544 KB |
Output is correct |
2 |
Correct |
463 ms |
644 KB |
Output is correct |
3 |
Correct |
830 ms |
520 KB |
Output is correct |
4 |
Correct |
698 ms |
528 KB |
Output is correct |
5 |
Correct |
531 ms |
524 KB |
Output is correct |
6 |
Correct |
404 ms |
544 KB |
Output is correct |
7 |
Correct |
467 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
4 ms |
620 KB |
Output is correct |
10 |
Correct |
0 ms |
628 KB |
Output is correct |
11 |
Correct |
584 ms |
544 KB |
Output is correct |
12 |
Correct |
460 ms |
640 KB |
Output is correct |
13 |
Correct |
457 ms |
640 KB |
Output is correct |
14 |
Correct |
438 ms |
528 KB |
Output is correct |
15 |
Correct |
51 ms |
620 KB |
Output is correct |
16 |
Correct |
62 ms |
672 KB |
Output is correct |
17 |
Correct |
91 ms |
700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
905 ms |
532 KB |
Output is correct |
2 |
Correct |
739 ms |
420 KB |
Output is correct |
3 |
Correct |
597 ms |
528 KB |
Output is correct |
4 |
Correct |
3 ms |
620 KB |
Output is correct |
5 |
Correct |
3 ms |
500 KB |
Output is correct |
6 |
Correct |
0 ms |
628 KB |
Output is correct |
7 |
Correct |
486 ms |
528 KB |
Output is correct |
8 |
Correct |
806 ms |
420 KB |
Output is correct |
9 |
Correct |
543 ms |
544 KB |
Output is correct |
10 |
Correct |
566 ms |
524 KB |
Output is correct |
11 |
Correct |
4 ms |
628 KB |
Output is correct |
12 |
Correct |
6 ms |
624 KB |
Output is correct |
13 |
Correct |
5 ms |
500 KB |
Output is correct |
14 |
Correct |
3 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
620 KB |
Output is correct |
16 |
Correct |
509 ms |
672 KB |
Output is correct |
17 |
Correct |
435 ms |
420 KB |
Output is correct |
18 |
Correct |
421 ms |
548 KB |
Output is correct |
19 |
Correct |
524 ms |
532 KB |
Output is correct |
20 |
Correct |
487 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
489 ms |
544 KB |
Output is correct |
2 |
Correct |
449 ms |
544 KB |
Output is correct |
3 |
Correct |
755 ms |
548 KB |
Output is correct |
4 |
Correct |
502 ms |
548 KB |
Output is correct |
5 |
Correct |
571 ms |
416 KB |
Output is correct |
6 |
Correct |
434 ms |
548 KB |
Output is correct |
7 |
Correct |
401 ms |
548 KB |
Output is correct |
8 |
Correct |
1 ms |
628 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
660 KB |
Output is correct |
11 |
Correct |
417 ms |
528 KB |
Output is correct |
12 |
Correct |
452 ms |
524 KB |
Output is correct |
13 |
Correct |
753 ms |
516 KB |
Output is correct |
14 |
Correct |
643 ms |
676 KB |
Output is correct |
15 |
Correct |
525 ms |
416 KB |
Output is correct |
16 |
Correct |
479 ms |
532 KB |
Output is correct |
17 |
Correct |
512 ms |
532 KB |
Output is correct |
18 |
Correct |
393 ms |
756 KB |
Output is correct |
19 |
Correct |
454 ms |
668 KB |
Output is correct |
20 |
Correct |
477 ms |
532 KB |
Output is correct |
21 |
Correct |
40 ms |
620 KB |
Output is correct |
22 |
Correct |
69 ms |
780 KB |
Output is correct |
23 |
Correct |
105 ms |
768 KB |
Output is correct |
24 |
Correct |
4 ms |
492 KB |
Output is correct |
25 |
Correct |
5 ms |
500 KB |
Output is correct |
26 |
Correct |
4 ms |
628 KB |
Output is correct |
27 |
Correct |
2 ms |
620 KB |
Output is correct |
28 |
Correct |
1 ms |
628 KB |
Output is correct |
29 |
Correct |
433 ms |
664 KB |
Output is correct |
30 |
Correct |
402 ms |
544 KB |
Output is correct |
31 |
Correct |
511 ms |
548 KB |
Output is correct |
32 |
Correct |
439 ms |
544 KB |
Output is correct |
33 |
Correct |
515 ms |
416 KB |
Output is correct |
34 |
Correct |
330 ms |
528 KB |
Output is correct |
35 |
Correct |
399 ms |
796 KB |
Output is correct |
36 |
Correct |
440 ms |
648 KB |
Output is correct |
37 |
Correct |
447 ms |
664 KB |
Output is correct |
38 |
Correct |
449 ms |
708 KB |
Output is correct |
39 |
Correct |
485 ms |
664 KB |
Output is correct |
40 |
Correct |
403 ms |
628 KB |
Output is correct |
41 |
Correct |
490 ms |
672 KB |
Output is correct |
42 |
Correct |
76 ms |
672 KB |
Output is correct |
43 |
Correct |
121 ms |
740 KB |
Output is correct |
44 |
Correct |
133 ms |
528 KB |
Output is correct |
45 |
Correct |
157 ms |
528 KB |
Output is correct |
46 |
Correct |
366 ms |
524 KB |
Output is correct |
47 |
Correct |
319 ms |
532 KB |
Output is correct |
48 |
Correct |
52 ms |
672 KB |
Output is correct |
49 |
Correct |
61 ms |
672 KB |
Output is correct |