#C3532. Marathon Water Stations

    ID: 46970 Type: Default 1000ms 256MiB

Marathon Water Stations

Marathon Water Stations

You are organizing a marathon where each runner may stop at various water stations along the route. Given the number of runners and the number of water stations, along with the details of which water stations each runner stopped at, your task is to track the runners stopping at each station.

For each water station, output the station number followed by the list of runner IDs (in ascending order) that stopped at that station. If no runner stopped at a particular station, simply output the station number.

Note: All station numbers are 1-indexed.

The mathematical representation for the station processing is as follows:

For each station \( i \) (\( 1 \leq i \leq M \)), let \( R_i \) be the set of runner IDs such that runner \( r \) stopped at station \( i \). Then, the output for station \( i \) is given by:

[ Output_i = i \quad \text{if} \quad R_i = \emptyset, ]

[ Output_i = i ; {sorted(R_i)} \quad \text{if} \quad R_i \neq \emptyset. ]

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  • The first line contains two integers \( N \) and \( M \): the number of runners and the number of water stations respectively.
  • The next \( N \) lines each describe a runner. Each such line begins with an integer representing the runner's ID, followed by an integer \( k \) denoting the number of water stations the runner stopped at, followed by \( k \) integers indicating the water station IDs.

outputFormat

Output \( M \) lines to standard output (stdout). The \( i\)-th line (1-indexed) should begin with the station number \( i \). If any runners stopped at station \( i \), follow it with a space and then the sorted list of runner IDs separated by spaces. If no runner stopped at station \( i \), output only the station number.

## sample
3 3
1 2 1 2
2 2 2 3
3 2 1 3
1 1 3

2 1 2 3 2 3

</p>