Skip to content

Commit 76a0a45

Browse files
authored
Merge pull request #1096 from AlgorithmWithGod/khj20006
[20251012] BOJ / P5 / Kaka & Bebe / 권혁준
2 parents 545cc67 + 2189810 commit 76a0a45

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int N, M;
6+
vector<vector<tuple<int, int, int>>> v(1000);
7+
vector<vector<int>> dist(1000, vector<int>(1001, -1));
8+
priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<>> q;
9+
10+
int main(){
11+
cin.tie(0)->sync_with_stdio(0);
12+
13+
for(cin>>N>>M;M--;) {
14+
int a,b,c,d;
15+
cin>>a>>b>>c>>d;
16+
v[a].emplace_back(b,c,d);
17+
v[b].emplace_back(a,c,d);
18+
}
19+
20+
dist[0][0] = 0;
21+
q.emplace(0,0,0);
22+
while(!q.empty()) {
23+
auto [d,n,k] = q.top(); q.pop();
24+
if(d > dist[n][k]) continue;
25+
for(auto [i,x,y]:v[n]) if(k + x <= 1000) {
26+
if(dist[i][k+x] == -1 || dist[i][k+x] > d+y) {
27+
dist[i][k+x] = d+y;
28+
q.emplace(d+y, i, k+x);
29+
}
30+
}
31+
}
32+
33+
int ans = -1;
34+
for(int i=0;i<=1000;i++) if(dist[N-1][i] != -1 && dist[N-1][i] <= 1000) {
35+
if(ans == -1) ans = dist[N-1][i] * i;
36+
else ans = min(ans, dist[N-1][i] * i);
37+
}
38+
cout<<ans;
39+
40+
}
41+
```

0 commit comments

Comments
 (0)