#C1851. Connected Users
Connected Users
Connected Users
Given an undirected graph representing connections between users, your task is to determine all users (including the target user) who are directly or indirectly connected to a specified target user. Two users are considered connected if there is a path between them. Using techniques such as breadth-first search (BFS), you should extract the connected component that contains the target user.
Formally, for a given target user \(t\), find the set \(S\) of all users such that there exists a path from \(t\) to any \(u \in S\) in the graph.
inputFormat
The input starts with an integer \(T\), representing the number of test cases. For each test case, the input is formatted as follows:
- An integer \(N\) denoting the number of connections.
- Next \(N\) lines each contain two integers \(u\) and \(v\) which indicate that there is a connection between user \(u\) and user \(v\).
- A single integer representing the target user.
All inputs are read from stdin.
outputFormat
For each test case, output a single line containing the user IDs of all users connected to the target user (including the target), sorted in ascending order. User IDs within a test case should be separated by a space. All outputs must be printed to stdout.
## sample2
5
1 2
2 3
3 4
4 5
5 6
1
4
10 11
11 12
12 13
9 13
9
1 2 3 4 5 6
9 10 11 12 13
</p>