Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

数据水了。。贴下代码。。

Posted by CUGB_kdq at 2012-07-14 16:27:46 on Problem 1125
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <iomanip>
#define PI acos(-1.0)
#define Max 2005
#define inf 1<<28
using namespace std;

int road[Max][Max],n;
void read()
{
    int x,y,m,i;
    for(i=1; i<=n; i++)
    {
        scanf("%d",&m);
        while(m--)
        {
            scanf("%d%d",&x,&y);
            road[i][x]=y;
        }
    }
}
void init()
{
    int i,j;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n;j++)
        road[i][j]=inf;
        road[i][i]=0;
    }
}
void floyd()
{
    int i,j,k;
    for(k=1;k<=n;k++)
    {
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(road[i][j]>road[i][k]+road[k][j])
                road[i][j]=road[i][k]+road[k][j];
            }
        }
    }
}
void solve()
{
    int i,j,k;
    floyd();
    int ans=inf;
    int ansnum;
    for(i=1;i<=n;i++)
    {
        int maxnum=-1;
        for(j=1;j<=n;j++)
        {
            if(i!=j)
            {
                if(maxnum<road[i][j])
                {
                    maxnum=road[i][j];
                }
            }
        }
        if(maxnum<ans)
        {
            ans=maxnum;
            ansnum=i;
        }
    }
    if(ans==inf)
    {
        cout<<"disjoint"<<endl;
    }
    else
    cout<<ansnum<<" "<<ans<<endl;
}
int main()
{
    int i,j,k,l,m;
    while(scanf("%d",&n)&&n)
    {
        init();
        read();
        solve();
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator