Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CTF Programming problem

Problem Statement
You are given a country represented as a graph where cities are nodes and roads are edges.
There are four types of cities, and you need to find the shortest path from a starting city to an
ending city. The city types and their properties are as follows:

1. Blocked City (B): You cannot pass through or enter these cities.
2. Normal City (N): Regular city with no special properties.
3. Type A Teleporting City (A): Contains a type A teleporting machine.
4. Type Z Teleporting City (Z): Contains a type Z teleporting machine.

Teleportation Rules:

● You can teleport from any type A city to any type Z city and vice versa.

There is exactly one start city (S) and one end city (E), both of which are normal cities.

Input Format

1. An integer N representing the number of cities.


2. An integer M representing the number of roads.
3. A string of length N where each character represents the type of each city:
○ 'S' for Start City
○ 'E' for End City
○ 'N' for Normal
○ 'B' for Blocked
○ 'A' for Type A Teleporting City
○ 'Z' for Type Z Teleporting City
4. M pairs of integers (u,v) representing a road between city u and city v.

The cities are numbered from 1 to N.

Output Format

● A single integer representing the length of the shortest path from the start city to the end
city, considering the teleportation rules. If no path exists, return -1.

Constraints
5
● 1≤𝑛, 𝑚≤10
Example :

Input:
88
SNANNNZE
12
23
34
45
56
67
78
24

Output:
4

path: 1 -> 2 -> 3 -> 7 -> 8

You might also like