#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
vector <int> bfs (int n, int nodo, vector <int> grafo[1000005]){
vector <int> aux(n);
bool visto[1000005];
queue <pair <int, int>> q;
for (int i = 0; i < 1000005; i++) visto[i] = false;
q.push({nodo, 0});
aux[nodo] = 0;
while (!q.empty()){
pair <int, int> act = q.front();
q.pop();
if (visto[act.first] == true) continue;
visto[act.first] = true;
if (grafo[act.first].size() <= 2){
for (auto i : grafo[act.first]) {
if (visto[i] != true){
q.push({i, act.second});
aux[i] = act.first + 1 + act.second;
}
}
} else {
int auxi = 2000;
aux[act.first] = 1e9;
for (auto i : grafo[act.first]) {
if (visto[i] == true) continue;
q.push({i, auxi});
aux[i] = act.first + 1 + auxi;
auxi += 2000;
}
}
}
return aux;
}
vector <int> label(int n, int k, vector <int> u, vector <int> v) {
vector <int> grafo[1000005];
for (int i = 0; i < u.size(); i++) {
int a = u[i], b = v[i];
grafo[a].pb(b);
grafo[b].pb(a);
}
for (int i = 0; i < n; i++){
if (grafo[i].size() == 1){
vector <int> labels = bfs(n, i, grafo);
//for (auto j : labels) cout << j << " ";
return labels;
}
}
return u;
}
int find_next_station(int s, int t, vector <int> c) {
int maxi = 1e9;
if (c.size() == 1) return c[0];
if (s != maxi){
if (t >= (s - (s % 2000)) + 2000 || t <= s) return min(c[0], c[1]);
else {
if (t > s) return max(c[0], c[1]);
else return min(c[0], c[1]);
}
} else {
for (auto i : c) {
if ((i - (i % 2000)) + 2000 >= t && i <= t) return i;
}
}
}
/*
int main(){
label(10, 1e9, {0, 1, 2, 3, 3, 3, 4, 6, 8}, {1, 2, 3, 4, 6, 8, 5, 7, 9});
}
*/
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:53:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < u.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:91:1: warning: control reaches end of non-void function [-Wreturn-type]
91 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
387 ms |
25260 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
33 ms |
24920 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=2003 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
421 ms |
25260 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
641 ms |
25004 KB |
Output is correct |
2 |
Incorrect |
480 ms |
25004 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
391 ms |
25260 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |