UVa 793 - Network Connections

793 - Network Connections

 * http://acm.uva.es/p/v7/793.html

Summary
We must help a network administrator determine which computers are connected to each other. We must handle two kinds of requests. There is a connection request, which puts a direct link between two machines, and a query request in which we must determine if two machines are able to communicate with one another through one or more hops.

Explanation
This is a pretty straight forward Union Set problem, with no real frills or interesting twists.

Gotcha's
This is a multiple input problem, even though not shown in the same input on the site.

Input
2

10 c 1 5 c 2 7 q 7 1 c 3 9 q 9 6 c 2 5 q 7 5

10 c 1 5 c 2 7 q 7 1 c 3 9 q 9 6 c 2 5 q 7 5

Output
1,2

1,2