Hi,
While I know nothing of plant P&ID, i think it's perfectly doable, may be using a custom graph structure, or resorting to a library like quickgraph, also it's no very dificult to implement an algorithm to find connected lines, just get the endpoints of a starting line and select recursiveley other lines at the end points of each line you are finding this way, you will need to take some care to mark visited nodes or lines in order to get a proper term condition of the recursive algorithm as usual with this kind of routines.
Gaston Nunez