HIHO #1093 : 最短路径·三:SPFA算法
来源:互联网 发布:阿里云发票造假 编辑:程序博客网 时间:2024/05/22 05:18
题目链接
#include<bits/stdc++.h>using namespace std;#define cl(a,b) memset(a,b,sizeof(a))#define LL long long#define pb push_back#define gcd __gcd#define For(i,j,k) for(int i=(j);i<k;i++)#define lowbit(i) (i&(-i))#define _(x) printf("%d\n",x)const int maxn = 1e6+10;const int inf = 1 << 28;vector<pair<int,int> > G[maxn];bool inq[maxn];int d[maxn];int spfa(int s,int t){ cl(inq,false); queue<int> q; for(int i=0;i<maxn;i++)d[i]=inf; q.push(s); d[s]=0; inq[s]=true; while(!q.empty()){ int u = q.front();q.pop(); for(int i=0;i<G[u].size();i++){ int v = G[u][i].first; int w = G[u][i].second; if(d[u]+w<d[v]){ d[v] = d[u] + w; if(!inq[v]){ inq[v]=true; q.push(v); } } } inq[u]=false; } return d[t];}int main(){ int n,m,s,t; cin>>n>>m>>s>>t; for(int i=0;i<m;i++){ int x,y,z;cin>>x>>y>>z; G[x].pb(make_pair(y,z)); G[y].pb(make_pair(x,z)); } cout<<spfa(s,t)<<endl; return 0;}
0 0
- HIHO #1093 : 最短路径·三:SPFA算法
- hiho刷题日记——第二十五天最短路径·三:SPFA算法
- hihoCoder 1093 : 最短路径·三:SPFA算法
- hihoCoder#1093 最短路径·三-SPFA算法
- hihoCoder 1093 最短路径·三:SPFA算法
- # hihocoder #1093 : 最短路径·三:SPFA算法
- hihocoder 1093 : 最短路径·三:SPFA算法
- hihocoder #1093 : 最短路径·三:SPFA算法
- hihoCoder - 1093 - 最短路径·三:SPFA算法
- hihoCoder 1093 : 最短路径·三:SPFA算法
- hihocoder 1093 : 最短路径·三:SPFA算法
- hihocoder#1093 : 最短路径·三:SPFA算法
- hihoCoder - 1093 - 最短路径·三:SPFA算法 (SPFA)
- hiho 25 最短路径 SPFA
- 题目1 : 最短路径·三:SPFA算法
- 最短路径算法---SPFA
- 最短路径----SPFA算法
- 【最短路径】SPFA算法
- TOJ 3120.Stock Exchange(LIS经典题目)
- 字符串实现大数相加
- 使用mingw编译live555
- 字符串,日期操作【javaScript】
- com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column '????' in
- HIHO #1093 : 最短路径·三:SPFA算法
- POJ 3255 Roadblock(SPFA寻找次短路)
- 欢迎使用CSDN-markdown编辑器
- 网络流 (费用流+拆边)——Transportation ( HDU 3667 )
- 修改tomcat命令行窗口名称
- C++primer plus 第11-12章笔记
- UVA - 572 Oil Deposits
- 通过TortoiseGit上传项目到GitHub
- 大数四则运算的C++实现