لینکهای مفید برای شرکت در مسابقه:
در طول مسابقه، میتوانید سؤالات خود را از قسمت «سؤال بپرسید» مطرح کنید.
Minutes after the telephone at “The Overweight Police” (also known as “Police-e fat ha”) headquarters rang, the officers moved out in helicopters to take care of the situation. It's a robbery. TIGH (TIGH Infamous Group of Hackers) are disappointed in their laptops this time and have set their green-text-on-a-black-background terminals aside to attack the KFC (KFC Federal Club) building in person! rooms and a roof combine for occupiable places in KFC. The rooms in KFC like the ones in any other ordinary building, are uniquely numbered from to . Roof is assigned the number .
There are staircases in the building which are the only means to move from one room (or roof) to another. Each staircase connects different rooms(or a room and the roof). It is known that there exists a unique way to go from the roof to any other room in the building if you only move down the staircases (Which means the setting of the rooms and the staircases among them forms a tree).
The victim is Gigi who He has been to a party last week. Just like everybody else, Gigi took countless pictures at they party with his sisters, mothers[citation needed], cousins, aunts and his brothers' wives. He's such a kind person that he took pictures with every single one of her daughters too (Unfortunately one of her daughters was not present at the party). As you know hackers continuously strive and plan to steal random family pictures from random people (not so random in this case. Coincidence? I guess not). TIGH is no exception. But wait! There's more! As you know “police-e fatha looks after everything”. They're not gonna let TIGH escape without a fight.
In seconds, events happen in order, each of which fits in exactly one of the following two categories:
Hence the name, police-e fatha don't like physical activities very much. Also they are pretty optimistic, so every time an overweight police jumps off from the helicopter into a room, she thinks about what is the maximum number of TIGH members that she could catch if she only used the staircases downwards considering she is “lucky”. An overweight police can catch a TIGH member if and only if they are in the same room at some moment.
The members of TIGH are as optimistic as fatha. When they steal some photos they would try to escape through the roof (using the command “$sudo teleport” which only works in the rooftops). Since TIGH members are not out of their minds, they will only use staircases upwards. they think to themselves what is the minimum number of fat polices that they have to escape from to reach
the rooftop considering they are “lucky”. A TIGH member has to escape from a fat police if and only if they are in the same room at some moment.
TIGH members are aware of the fact that the cops only move downwards, and the cops know that the hackers will only move towards the roof. Please note that nobody actually moves from her initial position. They only “think” about what would happen if everybody suddenly had the ability to move (with the conditions specified above). The term “lucky” in the above statements means that everyone thinks about her own best-case scenario.
For example a lucky situation for a cop would be just waiting in his initial node, and catch every TIGH member that tries to pass him. You can prove that this strategy yields the maximum number of hackers that can be caught by the cop. For a better understanding take a look at the samples.
The first line of the input will consist of two numbers and , then follow lines each of which describing a staircase in the building “from” room number “downward” to room number .
The next lines are of the form “” where . means that an overweight police is placed in the room number and means that a TIGH member steals photos from the room number .
Output integers in different lines, th of them is the answer to the question that the person in the th event asks herself.