## Toronto Navigator

View as PDF

Points: 10 (partial)
Time limit: 1.5s
Python 2.5s
Memory limit: 128M

Authors:
Problem type

As a Toronto resident for most, if not all of your life, you know that this city is notorious for its bad traffic and constant construction. Toronto has intersections and roads connecting those intersections. You live at intersection , and for the next days, you will either drive to a building located at a different intersection, or Toronto closes a road. However, the construction is seemingly going to take longer than days, so these roads will stay closed for the entire input. Is it possible to drive to every destination you want to arrive at?

#### Constraints

No further constraints.

All are unique and consist of only lowercase and capital ASCII characters, numbers, _, and no spaces. The length of all are at most 20 characters long.

#### Input Specifications

The first line will contain three space-separated integers, , , and .

The next lines will contain the integers , , followed by the string . and indicate there is a road connection between these two intersections, and indicates the name of the road.

The next line will contain the integer .

The next lines will queries of the type:

• c R, indicating road has been closed for construction, or
• t I, indicating you want to travel from your current intersection to intersection (). is always distinct from the current intersection.

#### Output Specifications

For every query of the type t I, output yes if it is possible to travel from to intersection or 401 time... otherwise. After every query of this type, you will end up at intersection for the next query regardless if it is possible to reach intersection .

#### Sample Input 1

6 6 2
1 2 A
2 3 B
2 4 C
3 4 D
4 5 E
5 6 F
5
t 6
c D
t 3
c A
t 1

#### Sample Output 1

yes
yes
401 time...

#### Sample Case 1 Explanation

You can travel to intersection 6 via C -> E -> F.

After road D closes, you can still travel to intersection 3 via F -> E -> C -> B.

After road A closes, intersection 1 becomes disconnected from the rest of the city, and is inaccessible.

Here is the graph of the sample test case above:

#### Sample Input 2

18 27 1
1 2 Steeles_Ave_1
2 3 Steeles_Ave_2
3 4 Steeles_Ave_3
4 5 Steeles_Ave_4
5 6 Steeles_Ave_5
7 8 Finch_Ave_1
8 9 Finch_Ave_2
9 10 Finch_Ave_3
10 11 Finch_Ave_4
11 12 Finch_Ave_5
13 14 Sheppard_Ave_1
14 15 Sheppard_Ave_2
15 16 Sheppard_Ave_3
16 17 Sheppard_Ave_4
17 18 Sheppard_Ave_5
1 7 Warden_Ave_1
7 13 Warden_Ave_2
2 8 Birchmount_Rd_1
8 14 Birchmount_Rd_2
3 9 Kennedy_Rd_1
9 15 Kennedy_Rd_2
4 10 Midland_Ave_1
10 16 Midland_Ave_2
5 11 Brimley_Rd_1
11 17 Brimley_Rd_2
6 12 McCowan_Rd_1
12 18 McCowan_Rd_2
9
c Steeles_Ave_1
t 8
c Finch_Ave_2
c Birchmount_Rd_2
c Birchmount_Rd_1
t 15
c Kennedy_Rd_2
c Sheppard_Ave_3
t 5

#### Sample Output 2

yes
yes
401 time...

#### Sample Case 2 Explanation

You can travel to intersection 8 by driving South down Warden and then making a left onto Finch.

After a section of Finch and Birchmount closes, you can travel to intersection 15 by driving West down Finch then making a left onto Warden, then making a left onto Sheppard.

After a section of Kennedy and Sheppard closes however, you are now stuck in a part of Scarborough disconnected from the rest! Guess you have to take the 401... (it's going to take you 2 hours trust me on this one)

Here's the map in question: