About 2019 ccf fifth question number 317 subtasks

First contact graph algorithms written by the title after testing the sample, but later submitted to always prompt an error, first hanging. . . Do not know when to find the bug

(The last system ( "pause") before the return is used for debugging in vs inside)

Gangster hope can help facie wrong Oh (just apply today's blog)

. 1 #include <the iostream>
 2 #include <algorithm>
 . 3  the using  namespace STD;
 . 4  #define INF 1001
 . 5  int A [ 10000 ] [ 10000 ]; // matrix 
. 6  BOOL kind [ 10000 ]; // record the node type 
. 7  int sort_array [ 10000 ];
 . 8  int main ()
 . 9  {
 10      int n-, m, K;
 . 11      CIN >> >> m >> n- K;
 12 is      for ( int i = 0; i < n; i++)
13         cin >> kind[i];
14     for (int i = 0; i < n; i++)
15         for (int j = 0; j < n; j++)
16             if (i == j)
17                 a[i][j] = 0;
18             else
19                 a[i][j] = inf;
20 
21     //创建图
22     for (int i = 0; i < m; i++)
23 is      {
 24          int P, Q, R & lt;
 25          CIN Q >> >> >> P R & lt;
 26 is          A [P - . 1 ] [Q - . 1 ] = R & lt;
 27          A [Q - . 1 ] [P - . 1 ] = R & lt;
 28      } // for each value of an adjacent side Weighting
 29  
30      // Floyd algorithm to calculate the shortest distance between each by two points 
31 is      for ( int K = 0 ; K <n-; K ++ )
 32          for ( int I = 0 ; I <n-; I ++ )
 33 is              for( Int J = 0 ; J <n-; J ++ )
 34 is              {
 35                  IF (A [I] [K] + A [K] [J] < 2003 && A [I] [K] + A [K] [J] < A [I] [J])
 36                      A [I] [J] = A [I] [K] + A [K] [J];
 37 [              }
 38 is  
39      for ( int I = 0 ; I <n-; I ++ ) // total of m cycles rounds of 
40      {
 41 is          int pointer = 0 ; // pointer to the write sort_array 
42 is          for ( int J = 0; J < 10000 ; J ++ )
 43 is          {
 44 is              sort_array [J] = INF;
 45          } // to all initialized to the maximum value 
46 is          for ( int J = 0 ; J <n-; J ++ )
 47          {
 48              IF (kind [J] )
 49              {
 50                  sort_array [pointer] = a [I] [J];
 51 is                  pointer ++ ;
 52 is              }
 53 is          } // at this time has the shortest distance to reach the active nodes write sort_array
 54 is  
55         // use sort function sort_array ascending sort 
56 is          sort (sort_array, sort_array + pointer);
 57 is          int SUM = 0 ;
 58          for ( int P = 0 ; P <K; P ++ )
 59          {
 60              IF (sort_array [P] < = 1000 )
 61 is                  SUM + = sort_array [P];
 62 is          }
 63 is          COUT SUM << << endl;
 64      }
 65      System ( " PAUSE " );
 66      return 0;
67 }

 

Guess you like

Origin www.cnblogs.com/cs-yxk/p/11488413.html