# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1064884 | thatsgonzalez | Stations (IOI20_stations) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define s second
#define f first
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;
}
vector<vector<int>> tree(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;
}
int main(){
label(5, 10, {0, 1, 1, 2}, {1, 2, 3, 4});
cout<<find_next_station(2,0,{4,1})<<endl;
return 0;
}