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

table [ j ] [min ]<maxint 少写个p

Posted by RedField at 2006-10-28 23:32:32 on Problem 2387
In Reply To:我的dijstraWA了30多回了……实在不知道为什么,高手帮忙看看吧,拜托了 Posted by:secretsh at 2006-10-28 23:22:12
> #include <string.h> 
> #include <iostream>
> using namespace std;
> const int maxn = 4110;
> const int maxint = 10000001;
> unsigned int nearvex[ maxn ],lowcost[ maxn ],table[ maxn ][ maxn ];  
> int n , tt;
> 
> void Dijkstra(int st,int end) 
> { 
>         int i,j;          
>         for(i=1;i<=n;i++) 
>                {
>                         nearvex[i] = 0; 
>                         lowcost[i] = table[ i ][st]; 
>              }
>           nearvex[ st ] = 1;
>           lowcost [ st ] = 0; 
>         for(i=1;i<=n;i++) 
>         { 
>                 int min = maxint; 
>                 int pmin = -1; 
>                 for(j=1;j<=n;j++) 
>                         if(nearvex[j] != 1 && lowcost[j] < min ) 
>                         { 
>                                 min = lowcost[j]; 
>                                 pmin = j; 
>                         } 
>                    if ( end == pmin ) return ; 
>                 if( pmin >=0 ) 
>                 {
>                     nearvex[pmin] = 1; 
>                      for(j=1;j<=n;j++) 
>                          if(nearvex[j] ==0  && (lowcost[pmin] + table[ j ][ pmin ] < lowcost[j]) &&  table [ j ] [min ]<maxint ) 
>                                 lowcost[j] = lowcost[pmin] + table[j][pmin]; 
>                 }             
>         } 
> } 
> 
> int main() 
> { 
>     int i , j , index1 , index2 , tmp;
>    cin>>n>>tt;
>         for ( i = 1 ; i <= n ; i ++ ) 
>             for ( j = 1 ; j <=n ; j ++ ) 
>                     table [ i ] [ j ] = table [ j ] [ i ] = maxint;
>         for ( i = 1 ; i <=n ; i ++ ) 
>             table [ i ] [ i ] = 0;
>                 
>         for ( i = 0 ; i < tt ; i ++ ) 
>         {  
>             cin>>index1>>index2>>tmp; 
>             if ( tmp < table [ index1 ] [index2 ] ) 
>                 table [ index1 ] [ index2 ] = table [ index2 ]  [index1 ]= tmp;
>         }
>         Dijkstra(1,n); 
>         cout<<lowcost [ n ] <<endl;
>    //cin>>n;
>     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