Pruning large graphs of stray nodes
问题 I have a graph consisting of about 35,000 nodes represented in plain text: node1 -> node35000 node29420 -> node35000 node2334 -> node4116 ... I'd like to trim it down by removing nodes that are not part of a chain at least three long. So if I had only 1 -> 2; 2 -> 3; 3 -> 4; 0 -> 4; I'd like to keep 1, 2, 3, and 4 (since 1 -> 2 -> 3 -> 4 is four nodes long) but discard 0, that is, remove 0 -> 4 . Any idea of a good way to do this? I tried a combination of Perl and shell functions but I think