1 #include<iostream>
2 #include<cstring>
3 #include<queue>
4 using namespace std;
5
6 int g[2501][2501];
7 int n;
8 int m;
9 int be;
10 int en;
11 int cost[2501];
12
13 struct node
14 {
15 int n;
16 int cost;
17 node(){}
18 node(int a, int b)
19 {
20 n = a;
21 cost = b;
22 }
23 };
24
25 int main()
26 {
27 cin >> n >> m >> be >> en;
28 for (int i = 1; i <= m; i++)
29 {
30 int a, b, c;
31 cin >> a >> b >> c;
32 g[a][b] = c;
33 g[b][a] = c;
34 }
35 node b(be, 0);
36 queue<node>q;
37 q.push(b);
38 memset(cost, 0x3f, sizeof(cost));
39 while (!q.empty())
40 {
41 node t = q.front();
42 q.pop();
43 for (int i = 1; i <= n; i++)
44 {
45 if (g[t.n][i] && t.cost + g[t.n][i] < cost[i])
46 {
47 node p(i, (cost[i] = g[t.n][i] + t.cost));
48 q.push(p);
49 }
50 }
51 }
52 cout << cost[en];
53 }