1/* Report the distance from src = ARGV[0] to dst = ARGV[1]
2 */
3BEG_G {
4  int dist[node_t];
5  node_t n, curn;
6  node_t src = node($G, ARGV[0]);
7  node_t dst = node($G, ARGV[1]);
8  $tvroot = src;
9  $tvtype = TV_bfs;
10}
11
12N {
13  curn = $;
14  if ($ == dst) {
15    printf ("dist from %s to %s is %d\n", src.name, dst.name, dist[dst]);
16    exit(0);
17  }
18}
19
20E {
21  if ($.head == curn) n = $.tail;
22  else n = $.head;
23  if (dist[n] == 0) dist[n] = dist[curn]+1;
24}
25