8000 Merge pull request #414 from neppiness/20183_1 · REDICALED/basic-algo-lecture@e128488 · GitHub
[go: up one dir, main page]

Skip to content

Commit e128488

Browse files
Merge pull request encrypted-def#414 from neppiness/20183_1
update: 0x1D 20183.cpp
2 parents b98d4c5 + 5145baf commit e128488

File tree

1 file changed

+68
-5
lines changed

1 file changed

+68
-5
lines changed

0x1D/solutions/20183.cpp

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,74 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : scsc3204
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/70a654102a304d8faa01b9e6866f8e66
44
#include <bits/stdc++.h>
55
using namespace std;
6+
using ll = long long;
67

7-
int main(void){
8+
const int NMX = 100'000;
9+
const int MMX = 500'000;
10+
11+
vector<pair<ll, int>> adj[MMX + 2]; // adj[cur] = {cost, nxt}
12+
ll dist[NMX + 2];
13+
14+
ll lo = 1, hi;
15+
int n, m, st, en; ll c;
16+
17+
bool solve(ll lim) {
18+
priority_queue < pair<ll, int>,
19+
vector<pair<ll, int>>,
20+
greater<pair<ll, int>> > pq;
21+
22+
memset(dist, 0x3f, sizeof(dist));
23+
24+
dist[st] = 0;
25+
pq.push({0, st});
26+
while(!pq.empty()) {
27+
auto [co, cur] = pq.top(); pq.pop();
28+
if(dist[cur] != co) continue;
29+
for(auto [d, nxt] : adj[cur]) {
30+
if(d > lim) continue;
31+
d += co;
32+
if(dist[nxt] <= d) continue;
33+
dist[nxt] = d;
34+
pq.push({d, nxt});
35+
}
36+
}
37+
38+
if( 1081E dist[en] > c) return 0;
39+
return 1;
40+
}
41+
42+
int main() {
843
ios::sync_with_stdio(0);
944
cin.tie(0);
10-
11-
}
45+
46+
cin >> n >> m >> st >> en >> c;
47+
48+
while(m--) {
49+
int u, v; ll cost;
50+
cin >> u >> v >> cost;
51+
adj[u].push_back({cost, v});
52+
adj[v].push_back({cost, u});
53+
hi = max(hi, cost);
54+
}
55+
56+
while(lo < hi) {
57+
ll mid = (lo + hi) / 2;
58+
if(solve(mid)) hi = mid;
59+
else lo = mid + 1;
60+
}
61+
62+
if(solve(lo)) cout << lo;
63+
else cout << -1;
64+
}
65+
/*
66+
최대 요금의 최솟값을 찾는 매개변수 탐색을 수행합니다(56-60번째 줄).
67+
68+
다익스트라 알고리즘을 통해 최단거리를 찾으면서
69+
간선 비용 상한보다 큰 비용의 간선은 사용하지 않도록 구현합니다(30번째 줄).
70+
71+
다익스트라 알고리즘을 수행한 후,
72+
목적지의 최소 비용과 가진 돈 C를 비교해
73+
성공, 실패를 구분합니다(38-39번째 줄).
74+
*/

0 commit comments

Comments
 (0)
0