Question Graph

Context:
There’s a network of computers. Each computer accepts connections at certain incoming port numbers and can make outgoing connections to a possibly different set of outgoing port numbers. Some computers are connected through cables to each other. Computer A can directly transmit data to computer B if and only if:
there is a direct cable connection between computer A and B,
there exists a port number X, that is an outgoing port on computer A and an incoming port on computer B.
Some of the computers are connected directly to the outside, unsafe network. If there is a way to connect to computer Z either directly or indirecly from the outside network, that computer Z is “at risk”. If there is no way to connect to computer Z from outside network, that computer is “safe”.
Question:
Write a program that given:
computers (each computer has incoming and outgoing port numbers),
cable connections between computers (a pair of computers),
computers accessible from outside network,
Print out all "safe” computers and all possible ways to access a specific computer from outside network.

Looks like a question of Connected Components.
For every computer connected to the unsafe network run a bfs/dfs search.
After all the computers directly to outside network have been searched,the nodes(computer) not visited are the safe one.Print them.
While searching the nodes maintain an array which contains all the nodes which are in between the connection from current node to the outside network.Print the array whenever a node is visited.