-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadixHeap-32bit.test.cpp
45 lines (43 loc) · 1.1 KB
/
RadixHeap-32bit.test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0596"
#include <vector>
#include <iostream>
#include <array>
#include <algorithm>
using namespace std;
#include "../../lib/15-queue/RadixHeap.cpp"
int main(void){
cin.tie(0);ios::sync_with_stdio(false);
int N,K; cin >> N >> K;
vector<int> C(N),R(N);
for(int i = 0; i < N; ++i) cin >> C[i] >> R[i];
vector<vector<int>> edge(N);
for(int i = 0; i < K; ++i) {
int A,B; cin >> A >> B;
A--,B--;
edge[A].push_back(B);
edge[B].push_back(A);
}
vector<vector<int>> dp(N,vector<int>(N+1,1<<30));
dp[0][0] = 0;
RadixHeap<pair<int,int>, unsigned int> pq({0,0});
pq.push({0,{0,0}});
while(pq.size()){
auto p = pq.pop();
int from = p.second.first;
int r = p.second.second;
if(r){
for(int to:edge[from]){
if(dp[to][r-1]>dp[from][r]){
dp[to][r-1]=dp[from][r];
pq.push({dp[to][r-1],{to,r-1}});
}
}
}
if(dp[from][R[from]]>dp[from][r]+C[from]){
dp[from][R[from]]=dp[from][r]+C[from];
pq.push({dp[from][R[from]],{from,R[from]}});
}
}
cout << *min_element(dp[N-1].begin(),dp[N-1].end()) << endl;
return 0;
}