POJ 1125 stockbroker Grapevine "Floyd"

Source: Internet
Author: User

Very naked Floyd.

#include <cstdio>

#include <string.h>

#include <algorithm>

#define MAXN 201

#define INF 100000

using namespace Std;

int map[maxn][maxn],n,x,y,m;;

int main ()

{

while (1)

{

scanf ("%d", &n);

if (n==0) break;

for (int i=1;i<=n;i++)

for (int j=1;j<=n;j++)

Map[i][j]=inf;

for (int i=1;i<=n;i++)

{

scanf ("%d", &m);

for (int j=1;j<=m;j++)

scanf ("%d%d", &x,&y), map[i][x]=y;

}

for (int k=1;k<=n;k++)

for (int i=1;i<=n;i++) if (k!=i)

for (int j=1;j<=n;j++) if (J!=k&&j!=i&&map[i][k]+map[k][j]<map[i][j])

MAP[I][J]=MAP[I][K]+MAP[K][J];

int ans=inf,ansj=-1;

for (int i=1;i<=n;i++)

{

int tem=-1;

for (int j=1;j<=n;j++)

{

if (Map[i][j]>tem&&map[i][j]!=inf) tem=map[i][j];

if (map[i][j]==inf&&i!=j) {tem=-1;break;}

}

if (tem<ans&&tem!=-1) ans=tem,ansj=i;

}

if (ansj==-1) printf ("disjoint\n"); else

printf ("%d%d\n", Ansj,ans);

}

return 0;

}

POJ 1125 stockbroker Grapevine "Floyd"

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.