[UVA10048]噪音恐惧症
题面略
试题分析:直接Floyd一下维护u到v的路径最大值最小就可以了,1A
代码:
#include<iostream> #include<cstring> #include<cstdio> #include<queue> #include<stack> #include<vector> #include<algorithm> //#include<cmath> using namespace std; const int INF = 9999999; #define LL long long inline int read(){ int x=0,f=1;char c=getchar(); for(;!isdigit(c);c=getchar()) if(c=='-') f=-1; for(;isdigit(c);c=getchar()) x=x*10+c-'0'; return x*f; } int N,M,Q; int dis[1001][1001]; int main(){ N=read(),M=read(),Q=read(); memset(dis,999999,sizeof(dis)); for(int i=1;i<=N;i++) dis[i][i]=0; for(int i=1;i<=M;i++){ int a=read(),b=read(); dis[a][b]=min(dis[a][b],read()); dis[b][a]=dis[a][b]; } for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) for(int k=1;k<=N;k++) dis[j][k]=min(dis[j][k],max(dis[j][i],dis[i][k])); while(Q--){ int a=read(),b=read(); if(dis[a][b]>=999999) puts("no path"); else printf("%d ",dis[a][b]); } return 0; }