Description
- Each graph consists of nodes and edges where
an edge is used to connect two nodes.
- For example, the graph in the right is a tree with 10 nodes.
- The arrow of an edge is used to specify the direction of that edge.
For example,
is an edge starting from node A to node B.
That information is stored as A,B,
which is called a node pair.
Note that A,B is not the same as B,A.
- In this way, we can store the graph in the right as
A,B A,C A,D C,D B,E D,F D,G D,H F,I G,I G,J,
where two adjacent node pairs are separated by one or more spaces.
- Since the order of node pairs is irrelevant, it can be stored as
C,D A,D A,B A,C B,E D,F D,G G,I G,J D,H F,I,...
- The name of a node consists of one or more non-space, and non-comma
characters.
We want to get the nodes without outgoing edges, that is,
nodes without edges starting from them.
|
| Raw Input
|
| Desired Output
| A,B A,C A,D C,D B,E D,F D,G D,H F,I G,I G,J
|
| E H I J
|
|
Script and Comments
Script1 [ 1] s/^([^ ,]+ +)*([^ ,]+),/\2\n&/
[ 2] /\n/!b
[ 3] :loop
[ 4] s/^([^\n]+)\n(.* |)\1(,?( +|$)|,)/\1\n\2/
[ 5] s/^([^\n]+)\n(.*,)\1( +|$)/\1\n\2\3/
[ 6] t loop
[ 7] D
| |
|