UVA10048 Audiophobia[Floyd变形]
2016-10-28 00:03
183 查看
UVA - 10048 Audiophobia |
C), S represents the number of streets and Q is the number of queries.Each of the next S lines contains three integers: c1,c2 and d indicating that the average sound
intensity level on the street connecting the crossings c1 and c2 (c1 ̸= c2) is d decibels.Each of the next Q lines contains two integers c1 and c2 (c1 ̸= c2) asking for the minimum sound
intensity level you must be able to tolerate in order to get from crossing c1 to crossing c2.The input will terminate with three zeros form C, S and Q.
OutputFor each test case in the input first output the test case number (starting from 1) as shown in the
sample output. Then for each query in the input print a line giving the minimum sound intensity level
(in decibels) you must be able to tolerate in order to get from the first to the second crossing in the
query. If there exists no path between them just print the line “no path”.Print a blank line between two consecutive test cases.Sample Input7931 2 50
1 3 60
2 4 120
2 5 90
3 6 50
4 6 80
4 7 70
5 7 40
6 7 140
172662
7631 2 50
1 3 60
2 4 120
3 6 50
4 6 80
5 7 40
751724
000Sample Output
Case #1 80 60 60
Case #2 40 no path 80
题意:求图上两点间最大权值最小的路径,输出最大权值最小
应该可以用最小生成树+LCA 然而本题n很小,直接floyd变形就行了 PS:白书上讲错了
// // main.cpp // uva10048 // // Created by Candy on 27/10/2016. // Copyright © 2016 Candy. All rights reserved. // #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> using namespace std; const int N=105,M=1005,INF=1e9; inline int read(){ char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();} return x*f; } int n,m,q,g ,u,v; int d ; void floyd(){ for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j) d[i][j]=g[i][j]?g[i][j]:INF; for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) d[i][j]=min(d[i][j],max(d[i][k],d[k][j])); } int main(int argc, const char * argv[]){ int cas=0; while(true){ n=read();m=read();q=read(); if(!n&&!m&&!q) break; if(cas) putchar('\n'); printf("Case #%d\n",++cas); memset(g,0,sizeof(g)); memset(d,0,sizeof(d)); for(int i=1;i<=m;i++){u=read();v=read();g[u][v]=g[v][u]=read();} floyd(); for(int i=1;i<=q;i++){ u=read();v=read(); if(d[u][v]==INF) puts("no path"); else printf("%d\n",d[u][v]); } } return 0; }
相关文章推荐
- UVA10048 Audiophobia (floyd变形)
- UVa 10048 Audiophobia【Floyd】
- UVa 10048 Audiophobia / floyd变形
- UVA - 10048 Audiophobia floyd的变形
- UVa 10048 (Floyd变形) Audiophobia
- uva 10048 Audiophobia floyd的变形
- Uva 10048 噪音恐惧症——Floyd变形
- 紫书例题 11-5 Uva 10048 Floyd变形或者Kruskal离线
- UVa10048 Audiophobia (Floyd)
- UVa - 10048 - Audiophobia ( Floyd 变形 )
- UVA 10048 Audiophobia(Floyd变形)
- 噪音恐惧症(Audiophobia,UVa10048)——floyd变形,最大最小化
- UVA - 10048 Audiophobia (floyd+dp)
- UVa 10048 Audiophobia(最短路&Floyd)
- uva 10048 - Audiophobia(floyd 的变形)
- uva 10048 - Audiophobia(floyd 的变形)
- UVa 10048 - Audiophobia 简单Floyd
- 11.3.4-uva10048-floyd变形-两点之间路径上最大边的最小值
- uva 10048 Audiophobia(最小生成树)
- uva 10048 Audiophobia(最小生成树)