标签:min 最短路 clu main color cst str style namespace
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; inline char gc() { static char buf[1 << 18], *fs, *ft; return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++; } inline int read(){ int num=0,f=1; char c=getchar(); while(!isdigit(c)){if(c==‘-‘) f=-1; c=getchar();} while(isdigit(c)){num=(num<<1)+(num<<3)+(c^48); c=getchar();} return num*f; } #define maxn 2000 int dis[maxn][maxn],n,m; inline int in(){ memset(dis,10,sizeof(dis)); n=read(); m=read(); for(int i=1;i<=m;i++){ int u,v,c; u=read(); v=read(); c=read(); dis[u][v]=c; } } inline int floyd(){ for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]); } inline int out(){ cout<<dis[1][n]; } int main(){ in(); floyd(); out(); } floyd可以处理多源最短路问题
标签:min 最短路 clu main color cst str style namespace
原文地址:http://www.cnblogs.com/79707536wc/p/7617471.html