#include "stations.h"
#include <cstdio>
#include <cassert>
#include <map>
#include <vector>
#include <algorithm>
////////
///////////////////
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef vector<bool> vb;
int tiempo;
vvi conexiones;
vi labeles;
void bfs(int ac, int ant, bool entrada){
tiempo++;
//cerr << ac << ' ' << tiempo << '\n';
if (entrada) labeles[ac]=tiempo;
for (int x:conexiones[ac]){
if (x!=ant){
bfs(x,ac,not entrada);
}
}
tiempo++;
//cerr << ac << ' ' << tiempo << '\n';
if (not entrada) labeles[ac]=tiempo+2000;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
//cerr<<"h";
vi res(n);
conexiones=vvi(n);
cerr<<0;
for (int i=0;i<n-1;i++){
conexiones[u[i]].push_back(v[i]);
conexiones[v[i]].push_back(u[i]);
}
cerr<<0;
int i=0;
while (conexiones[i].size()==2) i++;
cerr<<0;
int ant=-1;
for (int j=0;j<n;j++){
res[i]=j;
swap(i,ant);
for (int x:conexiones[ant]){
if (x!=i){
i=x;
break;
}
}
}
return res;
tiempo=-1;
conexiones=vvi(n);
for (int i=0;i<n-1;i++){
conexiones[u[i]].push_back(v[i]);
conexiones[v[i]].push_back(u[i]);
}
labeles=vi(n);
bfs(0,-1, 1);
//for (int x:labeles) cerr << x << ' ';
//cerr<<'\n';
return labeles;
}
int find_next_station(int ac, int obj, std::vector<int> vecinos) {
if (obj>ac) return ac+1;
else return ac-1;
obj%=2000;
bool entrada=(ac<2000);
ac%=2000;
sort(vecinos.begin(),vecinos.end());
if (vecinos.size()==1) return vecinos[0]; //arriba
if (entrada){
int izq=ac;
if (obj<izq) return vecinos[vecinos.size()-1]; //arriba
for (int x:vecinos){
if (x%2000>=obj) return x; //abajo
}
return vecinos[vecinos.size()-1]; //arriba
}
else{
int der=ac;
if (obj>der) return vecinos[0]; //arriba
for (int i=vecinos.size()-1;i>=0;i--){
int x=vecinos[i];
if (x%2000<=obj) return x; //abajo
}
return vecinos[0]; //arriba
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
580 ms |
480 KB |
Output is correct |
2 |
Correct |
501 ms |
584 KB |
Output is correct |
3 |
Correct |
909 ms |
488 KB |
Output is correct |
4 |
Correct |
694 ms |
400 KB |
Output is correct |
5 |
Correct |
578 ms |
400 KB |
Output is correct |
6 |
Correct |
468 ms |
476 KB |
Output is correct |
7 |
Correct |
466 ms |
484 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
464 KB |
Output is correct |
10 |
Correct |
2 ms |
476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
328 KB |
Invalid labels (duplicates values). scenario=0, label=0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
543 ms |
604 KB |
Output is correct |
2 |
Correct |
446 ms |
612 KB |
Output is correct |
3 |
Correct |
850 ms |
400 KB |
Output is correct |
4 |
Correct |
664 ms |
492 KB |
Output is correct |
5 |
Correct |
477 ms |
400 KB |
Output is correct |
6 |
Correct |
453 ms |
484 KB |
Output is correct |
7 |
Correct |
459 ms |
488 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Incorrect |
1 ms |
288 KB |
Invalid labels (duplicates values). scenario=1, label=0 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
931 ms |
400 KB |
Output is correct |
2 |
Correct |
680 ms |
476 KB |
Output is correct |
3 |
Correct |
566 ms |
400 KB |
Output is correct |
4 |
Correct |
3 ms |
480 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
288 KB |
Invalid labels (duplicates values). scenario=0, label=0 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
539 ms |
492 KB |
Output is correct |
2 |
Correct |
435 ms |
744 KB |
Output is correct |
3 |
Correct |
848 ms |
528 KB |
Output is correct |
4 |
Correct |
625 ms |
488 KB |
Output is correct |
5 |
Correct |
610 ms |
588 KB |
Output is correct |
6 |
Correct |
426 ms |
528 KB |
Output is correct |
7 |
Correct |
440 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
472 KB |
Output is correct |
10 |
Correct |
3 ms |
480 KB |
Output is correct |
11 |
Incorrect |
5 ms |
328 KB |
Invalid labels (duplicates values). scenario=0, label=0 |
12 |
Halted |
0 ms |
0 KB |
- |