3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a= array ( 1 => 0, 2 => 1, 3 => 2, 4 => 3, 5 => 1, 6 => 0 ); class node { var $children; public function __construct(){ $this->children = array(); } } $tree = array(); foreach ($a as $q => $p){ if(!isset($tree[$p])) $tree[$p] = new node; if(!isset($tree[$q])) $tree[$q] = new node; $mark[$p]=FALSE; $mark[$q]=FALSE; array_push($tree[$p]->children,$q); } function dfs(&$ans,$node){ global $tree, $mark; $mark[$node] = TRUE; $ans = array(); foreach($tree[$node]->children as $child) if(!$mark[$child]){ $ans[$child]=$child; dfs($ans[$child],$child); } } $parent=1; dfs($ans,$parent); echo($ans[0]); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 30
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 30
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 19
Branch analysis from position: 12
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/7rNhW
function name:  (null)
number of ops:  39
compiled vars:  !0 = $a, !1 = $tree, !2 = $p, !3 = $q, !4 = $mark, !5 = $parent, !6 = $ans
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   21     1        ASSIGN                                                   !1, <array>
   22     2      > FE_RESET_R                                       $9      !0, ->30
          3    > > FE_FETCH_R                                       ~10     $9, !2, ->30
          4    >   ASSIGN                                                   !3, ~10
   23     5        ISSET_ISEMPTY_DIM_OBJ                         0  ~12     !1, !2
          6        BOOL_NOT                                         ~13     ~12
          7      > JMPZ                                                     ~13, ->12
   24     8    >   NEW                                              $15     'node'
          9        DO_FCALL                                      0          
         10        ASSIGN_DIM                                               !1, !2
         11        OP_DATA                                                  $15
   25    12    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~17     !1, !3
         13        BOOL_NOT                                         ~18     ~17
         14      > JMPZ                                                     ~18, ->19
   26    15    >   NEW                                              $20     'node'
         16        DO_FCALL                                      0          
         17        ASSIGN_DIM                                               !1, !3
         18        OP_DATA                                                  $20
   27    19    >   ASSIGN_DIM                                               !4, !2
         20        OP_DATA                                                  <false>
   28    21        ASSIGN_DIM                                               !4, !3
         22        OP_DATA                                                  <false>
   29    23        INIT_FCALL                                               'array_push'
         24        FETCH_DIM_W                                      $24     !1, !2
         25        FETCH_OBJ_W                                      $25     $24, 'children'
         26        SEND_REF                                                 $25
         27        SEND_VAR                                                 !3
         28        DO_ICALL                                                 
   22    29      > JMP                                                      ->3
         30    >   FE_FREE                                                  $9
   43    31        ASSIGN                                                   !5, 1
   45    32        INIT_FCALL                                               'dfs'
         33        SEND_REF                                                 !6
         34        SEND_VAR                                                 !5
         35        DO_FCALL                                      0          
   47    36        FETCH_DIM_R                                      ~29     !6, 0
         37        ECHO                                                     ~29
   49    38      > RETURN                                                   1

Function dfs:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 23
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 23
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 22
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/7rNhW
function name:  dfs
number of ops:  25
compiled vars:  !0 = $ans, !1 = $node, !2 = $tree, !3 = $mark, !4 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   33     2        BIND_GLOBAL                                              !2, 'tree'
          3        BIND_GLOBAL                                              !3, 'mark'
   34     4        ASSIGN_DIM                                               !3, !1
          5        OP_DATA                                                  <true>
   35     6        ASSIGN                                                   !0, <array>
   36     7        FETCH_DIM_R                                      ~7      !2, !1
          8        FETCH_OBJ_R                                      ~8      ~7, 'children'
          9      > FE_RESET_R                                       $9      ~8, ->23
         10    > > FE_FETCH_R                                               $9, !4, ->23
   37    11    >   FETCH_DIM_R                                      ~10     !3, !4
         12        BOOL_NOT                                         ~11     ~10
         13      > JMPZ                                                     ~11, ->22
   38    14    >   ASSIGN_DIM                                               !0, !4
         15        OP_DATA                                                  !4
   39    16        INIT_FCALL_BY_NAME                                       'dfs'
         17        CHECK_FUNC_ARG                                           
         18        FETCH_DIM_FUNC_ARG                               $13     !0, !4
         19        SEND_FUNC_ARG                                            $13
         20        SEND_VAR_EX                                              !4
         21        DO_FCALL                                      0          
   36    22    > > JMP                                                      ->10
         23    >   FE_FREE                                                  $9
   41    24      > RETURN                                                   null

End of function dfs

Class node:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7rNhW
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN_OBJ                                               'children'
          1        OP_DATA                                                  <array>
   18     2      > RETURN                                                   null

End of function __construct

End of class node.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.12 ms | 1403 KiB | 16 Q