#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define s second
#define f first
vector<vector<int>> tree;
vector<vector<int>> dist;
int const inf = INT_MAX;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
for (int i = 0; i < n; i++) {
labels[i] = i;
}
tree.resize(n);
dist.assign(n,vector<int>(n,inf));
for(int i = 0; i<n-1; i++){
tree[u[i]].push_back(v[i]);
tree[v[i]].push_back(u[i]);
}
for(int i = 0; i<n; i++){
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
dist[i][i] = 0;
pq.push({0,i});
while(!pq.empty()){
int u = pq.top().s; int w = pq.top().f; pq.pop();
if(dist[i][u]!=w) continue;
for(auto &x: tree[u]){
if(dist[i][x] > dist[i][u] + 1){
dist[i][x] = dist[i][u] + 1;
pq.push({dist[i][x],x});
}
}
}
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
int mn = INT_MAX;
int res = -1;
for(auto &x: c){
if(dist[x][t]<mn){
mn = dist[x][t]; res = x;
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
356 ms |
16632 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
29 ms |
8536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
684 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
91 ms |
8536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |