Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
Tags
- ์ต๋จ ๊ฒฝ๋ก
- GCP
- ๋ฐ์ดํฌ์คํธ๋ผ
- dynamic debugging
- ์ฌ๊ท
- error
- ์ฐ์ ์์ ํ
- web
- BFS
- dfs
- ๋ฐฑํธ๋ํน
- CVE
- JPA
- ๋์ ํฉ
- Reversing
- ์คํ
- ๋ถํ ์ ๋ณต
- ์ด๋ถ ํ์
- ์์ ์ ๋ ฌ
- ๊ทธ๋ฆฌ๋
- thymeleaf
- OS
- ๋งต
- java
- DP
- ์๋ฎฌ๋ ์ด์
- ๋ฌธ์์ด
- ๊ตฌํ
- c++
- Spring
Archives
- Today
- Total
hades
[Baekjoon] 1916๋ฒ: ์ต์๋น์ฉ ๊ตฌํ๊ธฐ ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/1916
๐ ์ค๊ณ
์ธ์ ๋ฆฌ์คํธ๋ฅผ ํ์ฉํ์ฌ ๋ฐ์ดํฌ์คํธ๋ผ ์๊ณ ๋ฆฌ์ฆ์ผ๋ก ํด๊ฒฐํ ์ ์๋ค.
๋ค๋ง, ์ฐ์ ์์ ํ๋ฅผ ํ์ฉํ๋ฏ๋ก, ์ด๋ฏธ ์ด๋ ์ ์ ๊น์ง ๊ฐ๋๋ฐ ์ต์ ๋น์ฉ์ผ๋ก ๊ฐฑ์ ๋์์ ์๋ ์์ผ๋ฏ๋ก, ํ์ธ ํ skipํ๋ ๊ฒ์ด ํ์ํ๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ์ธ์ ํ ์ ์ ๊น์ง ๋ฐ๋ณต๋ฌธ์ ๋ ๋๊ฒ ๋์ด ์๊ฐ ์ด๊ณผ๊ฐ ๋ฐ์ํ๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int n, m, start, endd, cost, a, b;
vector<vector<pair<int, int>>> adj_list(1001);
vector<int> dist(1001, 1e9 + 7);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
void Dijkstra() {
dist[a] = 0;
pq.push({ 0, a });
while (!pq.empty()) {
int cur_cost = pq.top().first;
int cur_node = pq.top().second;
pq.pop();
if (cur_cost > dist[cur_node]) {
continue;
}
for (int i = 0; i < adj_list[cur_node].size(); i++) {
int next_node = adj_list[cur_node][i].second;
int next_cost = cur_cost + adj_list[cur_node][i].first;
if (dist[next_node] > next_cost) {
dist[next_node] = next_cost;
pq.push({ next_cost, next_node });
}
}
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> start >> endd >> cost;
adj_list[start].push_back({ cost, endd });
}
cin >> a >> b;
Dijkstra();
cout << dist[b] << "\n";
return 0;
}
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 11501๋ฒ: ์ฃผ์ (0) | 2024.08.07 |
---|---|
[Baekjoon] 11675๋ฒ: ํ์๋จธ์ (0) | 2024.08.06 |
[Baekjoon] 1753๋ฒ: ์ต๋จ๊ฒฝ๋ก (0) | 2024.08.05 |
[Baekjoon] 1181๋ฒ: ๋จ์ด ์ ๋ ฌ (0) | 2024.08.04 |
[Baekjoon] 1504๋ฒ: ํน์ ํ ์ต๋จ ๊ฒฝ๋ก (0) | 2024.08.03 |