I did something similiar last year with SQL. I had network with several sinks and sources and pipe direction didn't matter.
First i did SQL table #tree |source_id|target_id| (start point over start point or end point...), #closed table |id| and #reached table |id|. All id are pipes unique id
i inserted closed pipe id into #closed and first pipe id's from source to #reached table, then loop over #tree table until i didnt have anything to insert into #reached table. It is little bit slow way to do it but it works, only thing you need is tree
DECLARE @closed varchar(50)
SET @closed = '23'
DECLARE @root varchar(50)
SET @root = '42'
-- add all sources to reached
insert into #reached values ( @root ) -- substitute root id as needed
while ( @@rowcount > 0 ) begin
insert into #reached (id )
select distinct child as id
from tree e
join #reached p on p.id = e.parent collate database_default
e.child collate database_default not in ( select id from #reached )
AND e.child != @closed AND e.parent != @closed
-- change to : e.child not in #closed
select distinct parent as id
from tree e
join #reached p on p.id = e.child collate database_default
e.parent collate database_default not in ( select id from #reached )
AND e.parent != @closed AND e.child != @closed
That solves which pipes are connected to source or sources . It dosen't support several closed id , but it should be easy to fix.
Can't remember original author but i found base script from internet