[USACO07NOV]牛栏Cow Hurdles
题目大意:有一个有向图,有多个询问,每个询问给你a和b,要你求出a->b路径上最小的最大值
题解:因为是求点对之间的最小的最大值,可以用变形的Floyd来解,f[i][j]=min(f[i][j],max(f[i][k],f[k][j]))
C++ Code:
#include<cstdio> using namespace std; const int maxn=310; const int inf=0x7fffffff; int n,m,t; int f[maxn][maxn]; int max(int a,int b){return a>b?a:b;} 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 i=0;i<m;i++){ int a,b,c; scanf("%d%d%d",&a,&b,&c); f[a][b]=c; } for (int k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++)if (f[i][j]>max(f[i][k],f[k][j]))f[i][j]=max(f[i][k],f[k][j]); for (int i=0;i<t;i++){ int a,b; scanf("%d%d",&a,&b); printf("%d\n",(f[a][b]^inf)?f[a][b]:-1); } return 0; }