DepthFirstScan
DepthFirstScan[g,s,{event1->f1,event2->f2,…}] performs a depth-first scan of the graph g starting at the vertex s and evaluates fi whenever "eventi" occurs.
DepthFirstScan[g,{event1->f1,event2->f2,…}] performs a depth-first scan of the whole graph g.
DepthFirstScan[{v->w,…},…] uses rules v->w to specify the graph g.
Please visit the official Wolfram Language Reference for more details and examples on core symbols.