As you traverse, keep a current selection. For the -th node, replace your selection with probability . After seeing all nodes, each has probability of being selected.
Why does this work? Node 1 is kept with probability . The same holds for all other nodes by similar calculation.