bzoj1641[Usaco2007 Nov]Cow Hurdles 奶牛跨栏*

bzoj1641[Usaco2007 Nov]Cow Hurdles 奶牛跨栏

题意:

n点m边有向图,每次给出询问x,y求x到y路径中最大边权的最小值是多少。n≤500

题解:

floyd变形。

代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define inc(i,j,k) for(int i=j;i<=k;i++)
 5 #define maxn 310
 6 #define INF 0x3fffffff
 7 using namespace std;
 8 
 9 inline int read(){
10     char ch=getchar(); int f=1,x=0;
11     while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
12     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
13     return f*x;
14 }
15 int n,m,t,g[maxn][maxn];
16 int main(){
17     n=read(); m=read(); t=read(); inc(i,1,n)inc(j,1,n)g[i][j]=INF;
18     inc(i,1,m){int a=read(),b=read(); g[a][b]=read();}
19     inc(k,1,n)inc(i,1,n)inc(j,1,n)g[i][j]=min(g[i][j],max(g[i][k],g[k][j]));
20     inc(i,1,t){int a=read(),b=read(); printf("%d\n",g[a][b]==INF?-1:g[a][b]);}
21     return 0;
22 }

 

20160808

posted @ 2016-08-13 10:15  YuanZiming  阅读(181)  评论(0编辑  收藏  举报