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

Re:为何floyd过不了...........

Posted by Myzts at 2015-09-03 10:35:42 on Problem 3259
In Reply To:为何floyd过不了........... Posted by:xuesu at 2014-02-28 20:49:38
> #include <cstdio>
> #include <cstring>
> #include <iostream>
> using  namespace std;
> int f,n,m,w;
> int d[501][501];
> int main()
> {
>     scanf("%d",&f);
>     bool ans=false;
>     while(f--){
>         ans=false;
>         int x,y,temp;
>         scanf("%d %d %d",&n,&m,&w);
>         for(int i=0;i<=n;i++){
>             for( int j=0;j<=n;j++){
>                 d[i][j]=1000000;
>             }
>         }
>         while(m--){
>             scanf("%d %d %d",&x,&y,&temp);
>             d[x][y]=min(d[x][y],temp);
>             d[y][x]=min(d[y][x],temp);
>         }
>         while(w--){
>             scanf("%d %d %d",&x,&y,&temp);
>             temp=-temp;
>             d[x][y]=min(d[x][y],temp);
>         }
>         for(int i=0;i<=n;i++){
>             d[i][i]=0;
>         }
>         for(int i=1;i<=n;i++){
>             for(int j=1;j<=n;j++){
>                 for(int k=1;k<=n;k++){
>                     d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
>                 }
>             }
>             if(d[i][i]<0){
>                 ans=true;
>                 break;
>             }
>         }
>         if(ans){
>                 cout<<"YES"<<endl;
>         }
>         else {
>                 cout<<"NO"<<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