-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12763.cpp
73 lines (60 loc) · 1.65 KB
/
12763.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
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
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
int xxxx[]={-1,0,1,0,-1,1,1,-1};
int yyyy[]={0,1,0,-1,-1,1,-1,1};
struct Node {
int x, t, c;
};
void solve(){
int N;
int T, M; cin >> N >> T >> M;
int L; cin >> L;
vector<vector<tuple<int,int,int>>> edges(N+1);
while (L--) {
int a,b,c,d; cin >> a >> b >> c >> d;
edges[a].push_back({b,c,d});
edges[b].push_back({a,c,d});
}
auto compare = [](Node a, Node b){
return a.c >= b.c;
};
priority_queue<Node, vector<Node>, decltype(compare)> q(compare);
q.push({1, 0, 0});
int distances1[N+1]; memset(distances1, 0x3f, sizeof distances1);
int distances2[N+1]; memset(distances2, 0x3f, sizeof distances2);
while (q.size()) {
auto [x, t, c] = q.top(); q.pop();
if (x == N) {
cout << c;
return;
}
for (auto [nx, _t, _c] : edges[x]) {
if (_c + c > M || _t + t > T) continue;
if (distances2[nx] > _t + t) {
distances2[nx] = _t + t;
q.push({nx, _t + t, c + _c});
}
if (distances1[nx] > _c + c) {
distances1[nx] = _c + c;
q.push({nx, _t + t, c + _c});
}
}
}
cout << -1;
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
int T=1;
// cin >>T;
while (T--) {
solve();
cout << '\n';
}
return 0;
}