-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10217.cpp
More file actions
76 lines (70 loc) · 1.68 KB
/
10217.cpp
File metadata and controls
76 lines (70 loc) · 1.68 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <vector>
#include <queue>
#define INF 987654321
using namespace std;
class Node
{
public:
int idx, cost, time;
bool operator<(const Node &n) const
{
return time > n.time;
}
};
vector<vector<int>> dp;
vector<vector<Node>> graph;
priority_queue<Node> pq;
int main()
{
int T, N, M, K, u, v, c, d;
scanf("%d", &T);
while (T--)
{
int answer = INF;
scanf("%d %d %d", &N, &M, &K);
dp.assign(N + 1, vector<int>(M + 1, INF));
graph.assign(N + 1, vector<Node>(0, {0, 0, 0}));
while (K--)
{
scanf("%d %d %d %d", &u, &v, &c, &d);
graph[u].push_back({v, c, d});
}
dp[1][0] = 0;
pq.push({1, 0, 0});
while (!pq.empty())
{
int now = pq.top().idx;
int nowCost = pq.top().cost;
int nowTime = pq.top().time;
pq.pop();
if (now == N)
{
if (answer > nowTime)
{
answer = nowTime;
}
}
for (int i = 0; i < graph[now].size(); i++)
{
int to = graph[now][i].idx;
int toCost = graph[now][i].cost + nowCost;
int toTime = graph[now][i].time + nowTime;
if (toCost <= M && dp[to][toCost] > toTime)
{
dp[to][toCost] = toTime;
pq.push({to, toCost, toTime});
}
}
}
if (answer == INF)
{
printf("Poor KCM\n");
}
else
{
printf("%d\n", answer);
}
}
return 0;
}