Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The City of Technomania has created a maze game for the residents of the city. The maze is in the form of a tree. The
The City of Technomania has created a maze game for the residents of the city. The maze is in the form of a tree. The residents of the city consider even numbers lucky for them as the name of the city has an even number of duplicates n and a In the maze, there are N number of posts with each having either a green flag or a red flag Green flag G means you can move ahead in the maze and Red flag R means you cannot. There is a pavement between the two posts. There are a total of N pavements between the N posts.
Jess is a curious child and wants to play the maze game. However, she has an interesting take on the game. She wants to know the maximum number of posts she can reach from each post with the condition that she is allowed to change the even number of red flags. It means she is allowed to change etc. number of red flags but not allowed to change etc. number of red flags.
Example:
There are posts in the maze, N
There is one red flag POST and four green flags POST POST POST and POST The initial map of the maze is as below:
POST : If Jess starts her journey from post which is a green flag, she can cover posts at max. The path taken is given below:
Note: Jess cannot convert the red flag of Post to green as she only wants to convert the even number of red flags.
POST : Jess can cover the posts: POST POST and POST
POST : Post is a red flag and since there is no other red flag in the whole maze, Jess will not be able to convert this red flag into the green flag. As a result, she will not be able to cover any post and since post is also red, it will also not be considered.
POST : Jess can cover the posts: POST POST and POST
POST : Post is a green flag but Jess cannot reach any other post from here as she has a pavement to Post which is a red flag and cannot be converted to the green flag. The post covered by Jess is
Jess is not good with counting and wants you to help her with the calculations. Help Jess find the maximum number of posts she can reach with the given conditions.
Input Format
The first line of input consists of an integer, N representing the number of posts in the maze.
Next N lines each consists of two spaceseparated integers, x and y representing a pavement between the two posts.
The next line of input consists of a string of length N where the ith character represents the flag G or R at the ith post.
Character G represents the Green Flag and character R represents the Red Flag.
Constraints
N
x y N
Output Format
Print the maximum number of posts Jess can reach from each of the posts in separate lines. The line number represents the post number in the output.
Sample TestCase
Input
GGRGG
Output
Explanation
As explained in the example.
Sample TestCase
Input
RGRGR
Output
Explanation
The initial map of the maze is given below:
POST : POST and POST red flags can be converted to the green flags. Jess can cover posts: POST POST POST and POST
POST : Jess can cover posts: POST POST POST and POST A similar pavement as from Post is followed.
POST : Jess can cover posts: POST POST POST and POST A similar pavement as from Post is followed.
POST : Jess can cover posts: POST POST POST and POST A similar pavement as from Post is followed.
POST : Jess can cover two posts: POST and POST after converting red flags to green flags. She cannot move further as the Post has a red flag and she can convert only an even number of red flags.
Test Cases Result
Input Result Time Sec Memory Score
Sample Test Case
Passed
View
Sample Test Case
Failed
Hide
Test Case Input
RGRGR
Test Case Output
Expected Output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started