UA 10048 Audiophobia

Source: Internet
Author: User

UVA_10048

This topic is to find the path with the smallest maximum value in all reachable paths and output the maximum value. Based on the topic features, it is easier to use the Floyd algorithm to solve the problem.

#include<stdio.h>
#include<string.h>
int f[110][110];
int main()
{
int i,j,k,n,t,C,S,Q,u,v,temp;
t=0;
while(scanf("%d%d%d",&C,&S,&Q)==3)
{
if(C==0)
break;
for(i=1;i<=C;i++)
for(j=1;j<=C;j++)
{
if(i==j)
f[i][j]=0;
else
f[i][j]=-1;
}
for(i=0;i<S;i++)
{
scanf("%d%d%d",&u,&v,&k);
f[u][v]=f[v][u]=k;
}
for(k=1;k<=C;k++)
for(i=1;i<=C;i++)
for(j=1;j<=C;j++)
if(f[i][k]!=-1&&f[k][j]!=-1)
{
temp=f[i][k]>f[k][j]?f[i][k]:f[k][j];
if(f[i][j]==-1||temp<f[i][j])
f[i][j]=temp;
}
if(t++)
printf("\n");
printf("Case #%d\n",t);
for(i=0;i<Q;i++)
{
scanf("%d%d",&u,&v);
if(f[u][v]==-1)
printf("no path\n");
else
printf("%d\n",f[u][v]);
}
}
return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.