#include <iostream>
#include <vector>
#include <queue>
#define INF 1e9 //๋ฌดํ๋๋ฅผ ์๋ฏธํ๋ ๊ฐ์ผ๋ก 10์ต์ ์ง์ .
using namespace std;
vector<pair<int, int>>graph[5002];
int n, m, start, fin; //n=์ ์ ์ ๊ฐ์ m=๊ฐ์ ์ ๊ฐ์ start=์์ ๋
ธ๋ fin=๋ ๋
ธ๋
int d[5002]; //๊ฐ์ค์น๋ฅผ ์ ์ฅํ๋ ํ
์ด๋ธ
void dijkstra(int start) {
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>pq;
pq.push({ 0,start }); //์์ ๋
ธ๋๋ ๊ฐ์ค์น๊ฐ 0
d[start] = 0;
while (!pq.empty()) {
int dist = pq.top().first;
int now = pq.top().second;
pq.pop();
if (d[now] < dist) continue; //์ด๋ฏธ ๋ฐฉ๋ฌธํ ๋
ธ๋๋ ๋ฌด์.
for (int i = 0; i < graph[now].size(); i++) {
int neighbor = graph[now][i].first;
int neighborDist = dist+graph[now][i].second;
if (neighborDist < d[neighbor]) {
d[neighbor] = neighborDist;
pq.push({ neighborDist,neighbor });
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b, c; cin >> a >> b >> c;
graph[a].push_back({ b,c }); //a์์ b๊น์ง๊ฐ๋๋ฐ c๋งํผ์ ๊ฐ์ค์น๊ฐ ๋ ๋ค.
graph[b].push_back({ a,c }); //๋ฌด๋ฐฉํฅ(์๋ฐฉํฅ) ์ฒ๋ฆฌ
}
fill(d, d + 5001, INF);
cin >> start >> fin;
dijkstra(start);
cout << d[fin];
}
๋๊ธ