#B4020. Direct Train Query Problem
Direct Train Query Problem
Direct Train Query Problem
There are (N) cities in the country, numbered from (1) to (N). Every city has a high-speed rail station. Every day, there are (M) high-speed trains operating. The (i)-th train visits (l_i) cities in order, and the (j)-th city it visits is (c_{i,j}).
Two specific cities are given: city (a) (where Feng is located) and city (b) (where Qing is located). A train is said to be a direct high-speed train from city (a) to city (b) if it visits city (a) first and then later visits city (b).
Given the information of all (M) trains, count how many trains are direct from city (a) to city (b).
inputFormat
The input begins with a line containing four integers (N), (M), (a), and (b).
Each of the following (M) lines describes one train. The line begins with an integer (l_i) indicating the number of cities in this train's route, followed by (l_i) integers (c_{i,1}, c_{i,2}, \dots, c_{i,l_i}) representing the order in which the train visits the cities.
outputFormat
Output a single integer representing the number of trains that directly travel from city (a) to city (b).
sample
5 3 1 3
3 1 2 3
3 1 3 2
3 3 1 2
2