http://poj.org/problem?id=3615 (题目链接)
给出一张有向图,求从u到v最大边最小的路径的最大边。→_→不会说话了。。
好久没写Floyd了,水一发。邻接表都不用打。。。
// poj3615 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> #define LL long long #define inf 2147483640 #define Pi acos(-1.0) #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout); using namespace std; inline LL getint() { int f,x=0;char ch=getchar(); while (ch<=‘0‘ || ch>‘9‘) {if (ch==‘-‘) f=-1;else f=1;ch=getchar();} while (ch>=‘0‘ && ch<=‘9‘) {x=x*10+ch-‘0‘;ch=getchar();} return x*f; } const int maxn=310; int f[maxn][maxn],n,m,T; int main() { scanf("%d%d%d",&n,&m,&T); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (i!=j) f[i][j]=inf; for (int u,v,w,i=1;i<=m;i++) { scanf("%d%d%d",&u,&v,&w); f[u][v]=w; } for (int k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) f[i][j]=min(f[i][j],max(f[i][k],f[k][j])); for (int x,y,i=1;i<=T;i++) { scanf("%d%d",&x,&y); if (f[x][y]==inf) puts("-1"); else printf("%d\n",f[x][y]); } return 0; }
原文:http://www.cnblogs.com/MashiroSky/p/5965429.html