Problem Statement

There was a virus outbreak in ss, the city you are living in!

Some cities on the map are connected to each other by roads; and because there is no lockdown, if a virus is present in a city, then the virus would spread to all road-connected cities of that one city within just 11 day!

There are total of rr roads on the map. It has been dd days since the outbreak has started at your city ss. How many cities have been infected?

Input

Your first line will contain rr and dd as space-separated integers. rr represents the number of roads in the given map, and dd represents the number of days since the outbreak.

Your next line will contain ss, the name of the city in which the virus outbreak has started.

Your next rr lines will contain 22 space-separated city names, specifying that there is a road between the 22 cities where the virus could travel within a single day.

Output

A single integer representing the total number of cities affected by the virus after dd days.

Constraints

For all test cases:

  • 0≤r≤1050 \le r \le 10^5
  • 0≤d≤1030 \le d \le 10^3
  • All city names will comprise of only lower-case English letters.

Example 1

Input 1
14 2
clayton
burwood boxhill
mulgrave clayton
burwood glenwaverley
mulgrave rowville
rowville wantirnasouth
clayton chadstone
chadstone malverneast
clayton glenwaverley
malverneast moorabbin
burwood chadstone
camberwell burwood
springvale clayton
glenwaverley wantirnasouth
ringwood bayswater
Output 1
9

Example 2

Input 2
3 0
melbourne
melbourne sydney
sydney canberra
canberra melbourne
Output 2
1

Example 3

Input 3
24 4
nyc
charleston pittsburgh
montpelier albany
concord montpelier
portland augusta
pittsburgh dc
albany hartford
washingtondc richmond
richmond roanoke
philadelphia trenton
trenton newark
newark nyc
raleigh norfolk
newark hartford
portland boston
providence hartford
boston providence
norfolk richmond
raleigh durham
durham roanoke
harrisburg dc
philadelphia harrisburg
harrisburg dover
philadelphia atlanticcity
boston concord
Output 3
11

Example 4

Input 4
7 1000
earth
sun mercury
mercury venus
mars jupiter
jupiter saturn
saturn uranus
uranus neptune
neptune pluto
Output 4
1

Python Template

Code 1
r, d = map(int, input().split())
s = input()
roads = [tuple(input().split(" ")) for _ in range(r)]

# print(...)

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.