-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11085.cpp
60 lines (48 loc) · 1.19 KB
/
11085.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
int xxxx[]={-1,0,1,0,-1,1,1,-1};
int yyyy[]={0,1,0,-1,-1,1,-1,1};
typedef pair<int,int> pii;
struct Node {
int e, w, i;
};
void solve(){
int N, M;
cin >> N >> M;
int s,e; cin >> s >> e;
vector<vector<Node>> edges(N);
for (int i = 0; i < M; i++) {
int a,b,c; cin >> a >> b >> c;
edges[a].push_back({b,c,i});
edges[b].push_back({a,c,i});
}
priority_queue<pii> q;
bool visited[M]; memset(visited, 0, sizeof visited);
q.push({1000, s});
int result = -1;
while (q.size()) {
auto [y,x] = q.top(); q.pop();
if (x == e) {
cout << y;
return;
}
for (auto [nx, w, i] : edges[x]) {
if (visited[i]) continue;
int nw = min(w,y);
visited[i] = true;
q.push({nw,nx});
}
}
cout << result;
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
solve();
return 0;
}