Advertisement
Guest User

Graafide läbimine

a guest
Jan 13th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <?php
  2. define("NL", "
  3. ", true);
  4. $in=file('H:\djks1_108.in', FILE_IGNORE_NEW_LINES);
  5. $firstLine=explode(' ', $in[0]);
  6. $n=$firstLine[0];
  7. $m=$firstLine[1];
  8. $secondLine=explode(' ', $in[1]);
  9. $from=$secondLine[0];
  10. $to=$secondLine[1];
  11. unset($in[0]);
  12. unset($in[1]);
  13. $kaidud=array();
  14. $kaugus=array();
  15. $kaugused=array();
  16. foreach($in as $x) {
  17. $x=explode(' ', $x);
  18. $a=$x[0];
  19. $b=$x[1];
  20. $c=$x[2];
  21. if(!isset($kaugused[$a])) {
  22. $kaugused[$a]=array();
  23. }
  24. if(!isset($kaugused[$b])) {
  25. $kaugused[$b]=array();
  26. }
  27. $kaugused[$a][$b]=$c;
  28. $kaugused[$b][$a]=$c;
  29. $kaugused[$a][$a]=0;
  30. $kaugused[$b][$b]=0;
  31. }
  32. foreach($kaugused as $k=>$ka) {
  33. print $k.NL;
  34. foreach($ka as $key=>$value) {
  35. print ' '.$key.': '.$value.NL;
  36. }
  37. }
  38. print $from.NL;
  39. print $to.NL;
  40. kaugused($from);
  41. function kaugused($from) {
  42. global $kaugus;
  43. global $kaugused;
  44. global $kaidud;
  45. $kaidud[$from]=true;
  46. $jarjekord=array();
  47. foreach($kaugused[$from] as $key=>$value) {
  48. if(!isset($kaidud[$key])) {
  49. array_push($jarjekord, $key);
  50. }
  51. }
  52. sort($jarjekord);
  53. var_dump($jarjekord);
  54. }
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement