407155: GYM102697 126 Subway System

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

126. Subway Systemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
This problem is worth 35 points.

You're going to a city that has a large subway system. The subway system has $$$n$$$ lines, and each line has a certain number of stations. However, some stations are "transfer stations": multiple lines go through them.

Given a list of the stations that each subway line goes through, your task is to figure out how many transfer stations exist throughout the subway system.

Note that "loop lines" that start and end at the same station may appear in the input, and stations that are the start and end of the loop but have no other lines going through them do not count as transfer stations. For a station to be a transfer station, it has to have multiple distinct lines going through it.

Input

The first line of input contains a single positive integer $$$n$$$: the number of lines in the subway system.

The next $$$n$$$ test cases each consist of two lines of input.

The first line consists of a single positive integer $$$m$$$: the number of stations in the given subway line

The next line contains $$$m$$$ space-separated station names, representing the route of the given subway line. The subway line might be a loop line.

Output

Output a single positive integer $$$s$$$: the number of transfer stations in the subway system. Then, output $$$s$$$ station names: the name of each transfer station in the subway system, in alphabetical order.

ExamplesInput
6
7
Vienna EastFallsChurch Rosslyn MetroCenter LenfantPlaza StadiumArmory NewCarrolton
7
WiehleRestonEast EastFallsChurch Rosslyn MetroCenter LenfantPlaza StadiumArmory LargoTownCenter
8
FranconiaSpringfield KingStOldTown Pentagon Rosslyn MetroCenter LenfantPlaza StadiumArmory LargoTownCenter
5
BranchAvenue LenfantPlaza GalleryPlace FortTotten Greenbelt
6
Huntington KinStOldTown Pentagon LenfantPlaza GalleryPlace FortTotten
5
ShadyGrove MetroCenter GalleryPlace FortTotten Glenmont
Output
EastFallsChurch
FortTotten
GalleryPlace
LargoTownCenter
LenfantPlaza
MetroCenter
Pentagon
Rosslyn
StadiumArmory
Input
3
5
EastStation NorthStation WestStation SouthStation EastStation
2
WestStation CenterStation
2
NorthStation CenterStation
Output
CenterStation
NorthStation
WestStation
Note

Can you figure out which city has the subway system described in the first test case?

加入题单

上一题 下一题 算法标签: