fork download
  1. {+--------------------------------------------------------------------------+}
  2. {| The Textbook in Data Structure, Algorithms and Programming |}
  3. {| http://w...content-available-to-author-only...c.jp/~hoangle/DSAPTextbook/ |}
  4. {| |}
  5. {| Program: Finding_the_Minimum_Spanning_Tree_using_Kruskal_Algorithm |}
  6. {| Written by Le Minh Hoang |}
  7. {| Email: dsaptextbook@gmail.com |}
  8. {+--------------------------------------------------------------------------+}
  9.  
  10. {$MODE DELPHI} (*This program uses 32-bit Integer [-2^31 .. 2^31 - 1]*)
  11. program Finding_the_Minimum_Spanning_Tree_using_Kruskal_Algorithm;
  12. (*
  13. IMPORTANT NOTES FOR COMPATIBILITY:
  14. ==================================
  15. - This program is especially written for running under Windows 32 bit and
  16.   Free Pascal IDE. Therefore, 32-bit Integer type is used to result in the
  17.   best performance with the {$MODE DELPHI} compiler directive of FPK for
  18.   Windows.
  19. - If you use Borland Turbo Pascal 7 for DOS, you may have to reduce the
  20.   data structure to deal with the limited memory. In addition, BP7 does not
  21.   support 32-bit Integer type, it causes some Integer variables would have
  22.   to be converted into LongInt variables.
  23. - If you prefer to compile under Delphi, you can simply convert the source
  24.   code as follows:
  25.   + Replace the type "Text" with the type "TextFile"
  26.   + Change all procedure calls "Assign(., .)" to "AssignFile(., .)" and
  27.   "Close(.)" to "CloseFile(.)"
  28.   + Remove the {$MODE DELPHI} and add the {$APPTYPE CONSOLE} compiler
  29.   directive to the beginning of this program
  30. -----------------------------------------------------------------
  31. Please report any errors to: dsaptextbook@gmail.com, MANY THANKS!
  32. -----------------------------------------------------------------
  33. *)
  34. const
  35. InputFile = '';
  36. OutputFile = '';
  37. maxV = 1000;
  38. maxE = (maxV - 1) * maxV div 2;
  39. type
  40. TEdge = record
  41. u, v, c: Integer;
  42. Mark: Boolean;
  43. end;
  44. var
  45. e: array[1..maxE] of TEdge;
  46. Lab: array[1..maxV] of Integer;
  47. n, m: Integer;
  48. Connected: Boolean;
  49.  
  50.  
  51. procedure PrintResult;
  52. var
  53. i: Integer;
  54. begin
  55. for i:=35 downto 0 do WriteLn(i);
  56. end;
  57.  
  58. begin
  59. PrintResult;
  60. end.
  61.  
Success #stdin #stdout 0s 5288KB
stdin
7 21
1 2 547152
1 3 509157
1 4 539282
1 5 541645         
1 6 458433
1 7 385173

2 3 131528
2 4 92735
2 5 150511
2 6 94440
2 7 194542
3 4 216600
3 5 272401
3 6 157176
3 7 124077
4 5 57785
4 6 97323
4 7 242232
5 6 136663
5 7 283862
6 7 147426
stdout
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0