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

哈哈,0ms,菜鸟也有好运哪!!

Posted by slow at 2011-01-05 15:32:13 on Problem 1125
#include<iostream>
#include<stdio.h>
#include<cstring>
//using namespace std;
#define info 1<<29
int f[1234];
int find(int x)
{
 while(x!=f[x])    
   x=f[x];
 return x;  
}
int Union(int x,int y)
{
  int xx=find(x);
  int yy=find(y); 
  if(xx!=yy)
  f[xx]=yy;
  return 1;   
}
int main()
{
   int dis[102][102],i,n,j,k,N,max,min,p,t,a[12345];  
   while(scanf("%d",&n)!=EOF)
     { 
       memset(a,0,sizeof(a));   
     //  memset(f,0,sizeof(f));                    
       if(n==0) break;
       for(i=1;i<=n;i++)
       f[i]=i;                       
       for(i=1;i<=n;i++)
       { 
        for(j=1;j<=n;j++)
         {
           if(i==j)
           dis[i][j]=0;
           else
           dis[i][j]=info;               
           }
        }                 
       for(i=1;i<=n;i++)                   
         {               
          scanf("%d",&N);
          for(j=1;j<=N;j++)       
            {       
              scanf("%d%d",&p,&t);
              Union(i,p);
              if(dis[i][p]>t)
              dis[i][p]=t;      
            }     
         }  
      for(k=1;k<=n;k++) 
        for(i=1;i<=n;i++)
          for(j=1;j<=n;j++)
            {
             if(dis[i][j]>dis[i][k]+dis[k][j])               
             dis[i][j]=dis[i][k]+dis[k][j];
            }  
     for(k=1;k<=n;k++)
       {
       max=0;               
       for(j=1;j<=n;j++)
         if(dis[k][j]>max)       
           {      
            max=dis[k][j];
            a[k]=max;
           }                 
       }
       min=info;
       int ff;
     for(k=1;k<=n;k++)
       {
       if(a[k]<min) 
       {min=a[k]; ff=k;}               
       }
       int flag=0;
     for(i=1;i<=n;i++)
      if(find(1)!=find(i))
        flag=1; 
     if(flag==1) 
     {
     printf("disjoint\n");//<<endl;
     continue;            
     }    
     printf("%d %d\n",ff,min);    
    }    
 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