-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj10217.cpp
More file actions
54 lines (43 loc) · 1.09 KB
/
boj10217.cpp
File metadata and controls
54 lines (43 loc) · 1.09 KB
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
46
47
48
49
50
51
52
53
54
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int INF = 1999999999;
int T;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while(T--){
int n, m, k;
vector<pair<int,int>>minimum(101,{INF,INF});
vector<pair<int,pair<int,int>>>v[101];
priority_queue<pair<int,pair<int,int>>>pq;
cin >> n >> m >> k;
for(int i = 0; i < k; i++){
int a, b, c, d;
cin >> a >> b >> c >> d;
v[a].push_back({b,{c,d}});
}
pq.push({0,{0,1}});
while(!pq.empty()){
int dis = -pq.top().first;
int paid = pq.top().second.first;
int now = pq.top().second.second;
pq.pop();
if(paid > m) continue;
if(minimum[now].first <= dis || minimum[now].second <= paid) continue;
else minimum[now] = {dis,paid};
for(int i = 0; i < v[now].size(); i++){
int next = v[now][i].first;
int time = v[now][i].second.first;
int cost = v[now][i].second.second;
pq.push({-dis-time,{paid+cost,next}});
}
}
if(minimum[n].first == INF) cout << "Poor KCM\n";
else cout << minimum[n].first << '\n';
}
}