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 IceKingdom at 2008-10-30 12:14:13 on Problem 3013
调了我4个小时,我真的试了很多很多的数据,可是为什么老是WA呢
???
我代码,好心人,帮帮忙吧。。。感激不尽啊啊啊
Dijsktra + Heap 
哪里有错误呢?
program         Big_Christmax_Tree ;
const   maxn = 120000 ;
        infinity = 100000000000000 ;
type    link = ^node ;
        node = record  d : int64;  w : int64;  next : link ;  end ;
        heaptype = record  dist : int64;  pointer : int64;  end ;
        element = array[0..1000] of int64 ;
var     vertex : array[1..maxn] of link ;
        weight : array[1..maxn] of int64;
        h : array[1..maxn] of heaptype ;
        a : array[1..maxn] of int64;
        chosen : array[1..maxn] of boolean ;
        ans , n , m , num , testcase : int64;


procedure       go_up( s , t : longint) ;
var     ti , tj : int64;  x : heaptype ;
begin
        if  s >= t  then  exit ;
        tj := t ;  ti := tj shr 1 ;  x := h[tj] ;

        while  ti >= s  do
         if  x.dist < h[ti].dist
          then  begin
           a[h[ti].pointer] := tj ;
           h[tj] := h[ti] ;  tj := ti ;  ti := tj shr 1 ;
          end
          else  break ;

        h[tj] := x ;  a[x.pointer] := tj ;
end ;

procedure       go_down( s , t : int64) ;
var     ti , tj : int64;  x : heaptype ;
begin
        if s >= t  then  exit ;
        ti := s ;  tj := ti shl 1 ;  x := h[ti] ;

        while  tj <= t  do begin
         if  ( tj < t )  and  ( h[tj+1].dist < h[tj].dist )  then  inc( tj ) ;
         if  x.dist > h[tj].dist
          then  begin
           a[h[tj].pointer] := ti ;
           h[ti] := h[tj];  ti := tj ;  tj := ti shl 1 ;
          end
          else  break ;
        end ;

        h[ti] := x ;  a[x.pointer] := ti ;
end ;

procedure       enter ;
var     i : longint ;  x , y , k : int64;  p : link ;
begin
        fillchar( vertex , sizeof( vertex ) , 0 ) ;  fillchar( chosen , sizeof( chosen ) , 0 ) ;

        readln( n , m ) ;
        for  i := 1 to n  do read( weight[i] ) ;
        for  i := 1 to m  do begin
         readln( x , y , k ) ;
         if  x <> y
          then  begin
           new( p ) ;  p^.d := y ;  p^.w := k ;  p^.next := vertex[x] ;  vertex[x] := p ;
           new( p ) ;  p^.d := x ;  p^.w := k ;  p^.next := vertex[y] ;  vertex[y] := p ;
          end ;
        end ;

        for  i := 1 to n - 1 do begin
         h[i].dist := infinity ;  h[i].pointer := i + 1 ;  a[i + 1] := i ;
        end ;
        h[n].dist := 0 ;  h[n].pointer := 1 ;  a[1] := n ;  chosen[1] := true ;  num := n - 1 ;

        p := vertex[1] ;
        while  p <> nil  do begin
         if  p^.w < h[a[p^.d]].dist
          then  begin
           h[a[p^.d]].dist := p^.w ;
           go_up( 1 , a[p^.w] ) ;
          end ;
         p := p^.next ;
        end ;
end ;

procedure       solve ;
var     i : longint ; p : link ;  d : heaptype ;
begin
        for  i := 1 to n-1 do begin

         p := vertex[h[1].pointer] ;
         while  p <> nil  do begin
          if  not chosen[p^.d]  and  ( h[1].dist + p^.w < h[a[p^.d]].dist )
           then  begin
            h[a[p^.d]].dist := h[1].dist + p^.w ;
            go_up( 1 , a[p^.d] ) ;
           end ;
          p := p^.next ;
         end ;

         chosen[h[1].pointer] := true ;  a[h[1].pointer] := num ;  a[h[num].pointer] := 1 ;
         d := h[1] ;  h[1] := h[num] ;  h[num] := d ;  dec( num ) ;
         go_down( 1 , num ) ;

        end ;
end ;

procedure       print ;
var     i , j : longint ;  st : string ;
begin
          ans := 0 ;
          for  i := 1 to n  do
           if  h[a[i]].dist>=infinity
            then  begin
             ans := -1 ;  break ;
            end
            else
             ans := ans + weight[i] * h[a[i]].dist ;
          if ans = -1
           then writeln('No Answer')
           else writeln( ans ) ;
end ;

begin
        assign(input,'t3013.in') ;  reset(input) ;  assign(output,'t3013.out') ;  rewrite(output) ;

         readln( testcase ) ;
         while  testcase > 0  do begin
          dec( testcase ) ;
          enter ;
          solve ;
          print ;
         end ;

        close(input) ;  close(output) ;
end .



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