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 baicaited at 2009-05-02 12:14:39 on Problem 1125
In Reply To:我晕,死在while(cin>>n)上面了 Posted by:baicaitest at 2009-05-02 11:57:24
1本来想定义0为inf的,怎么也过不了,然后直接把0改成0xfffff,就过了。

附代码
#include <iostream>//1-0转换 不连通判断 
using namespace std;
int dis[105][105];
int n,N;

void floyd(){
     for (int k=0;k<n;k++)
         for (int i=0;i<n;i++)
             for (int j=0;j<n;j++)
             {
                 if (i!=j)
                 if (dis[i][k]!=0&&dis[k][j]!=0&&dis[i][k]+dis[k][j]<dis[i][j])
                    dis[i][j]=dis[i][k]+dis[k][j];
             }
}

int main()
{
    while (cin>>n&&n){
          for (int i=0;i<n;i++)
            for (int j=0;j<n;j++)
                dis[i][j]=0;
          for (int i=0;i<n;i++){
              cin>>N;        
              for (int j=0;j<N;j++){
                  int temp;
                  cin>>temp;
                  cin>>dis[i][temp-1];
              }
          }
        floyd();
          int node,n2=0;
        for (int j=0;j<n;j++){
            int m2=0;
            for (int k=0;k<n;k++){
                if (j!=k){
                          if (dis[j][k]==0) {m2=0;break;}
                          if (dis[j][k]>m2) m2=dis[j][k];
                }
            }
            if (m2)
            if (m2<n2||n2==0) {n2=m2;node=j+1;}
        }
        if (!n2) {cout<<"disjoint"<<endl;}
        else {cout<<node<<" "<<n2<<endl;}  
        }
        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