洛谷 1396 营救

来源:互联网 发布:作业做不来用什么软件 编辑:程序博客网 时间:2024/05/23 01:16
//最小瓶颈路,用SPFA。 #include<bits/stdc++.h>using namespace std;const int maxn = 100010; int n, m, s, t, tot;int d[maxn], st[maxn];//d[]表示到该点路上最大值的最小值。 bool vis[maxn];queue<int> q;struct node{    int v, w, nxt;} edge[2*maxn];inline void in(int x, int y, int z){    edge[++tot].v = y;    edge[tot].w = z;    edge[tot].nxt = st[x];    st[x] = tot;}inline void spfa(){    memset(d, 0x3f3f3f3f, sizeof(d));    q.push(s);    vis[s] = 1;    d[s] = 0;    while(!q.empty()){        int now = q.front(); q.pop();        vis[now] = 0;        for(int i = st[now]; i; i = edge[i].nxt){            int to = edge[i].v;            if(max(d[now], edge[i].w) < d[to]){//重点理解。                 d[to] = max(d[now], edge[i].w);                vis[to] = 1;                q.push(to);            }        }    }}int main(){    scanf("%d%d%d%d", &n, &m, &s, &t);    for(int i = 1, x, y, z; i <= m; i++){        scanf("%d%d%d", &x, &y, &z);        in(x, y, z);        in(y, x, z);    }    spfa();    printf("%d\n", d[t]);    return 0;} 
原创粉丝点击