Logo
(追記) (追記ここまで)

10380번 - Instruction 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB31191758.621%

문제

Ingrid is a head of a big railway station and, among other duties, is responsible for routing trains to the right platforms. The station has one entrance, and there are many switches that direct trains to other switches and platforms.

Each switch has one inbound track and two outbound tracks, platforms have one inbound track, and station entrance has one outbound track. Each outbound track is connected to one inbound track and vice versa. Every switch and platform is reachable from station entrance.

Platforms have a rail dead ends and you may assume that trains disappear from the platform immediately after arriving to it.

Each morning Ingrid looks at the timetable and writes switch toggling instruction: when and which switch to toggle. She would like to automate this process to save a lot of time.

입력

The first line of the input file contains a single integer n — the total number of switches and platforms on the station (3 ≤ n ≤ 51).

The i-th of the following n lines describes a switch or a platform with an index i. Description starts with a character ‘p’ for a platform or ‘s’ for a switch. Next number qi indicates the number of the switch the inbound track is connected to or 0 if it is connected to station entrance (0 ≤ qi < i). Description of the platform also contains a unique lowercase English letter — the platform identifier.

Trains spend exactly one minute to move between two connected switches or a switch and a platform. In the morning, each switch is toggled in a way that a train would pass to the one of the two outbound tracks connected to the switch/platform with the lower number.

Next line of the input file contains a single integer m (1 ≤ m ≤ 1000) — the number of trains in timetable.

Each of the following m lines contains integer ai (0 ≤ ai ≤ 10 000; ai > ai−1) — the time in minutes when a train arrives to the station entrance, and the letter pi — identifier of the destination platform for this train.

출력

In the first line output integer c — the number of commands in the switch toggling instruction. For each command, output two integers si and ti (1 ≤ si ≤ n; 0 ≤ ti ≤ 109) — the number of the switch and the time to toggle it. Assume that the switch is toggled between minutes ti − 1 and ti.

Output commands in order of non-decreasing time. The number of commands should not exceed 100 000.

제한

예제 입력 1

7
s 0
s 1
s 1
p 2 a
p 2 b
p 3 c
p 3 d
5
0 a
1 c
3 b
4 a
5 d

예제 출력 1

6
1 2
1 4
2 4
2 6
1 6
3 7

예제 입력 2

5
s 0
p 1 y
s 1
p 3 z
p 3 x
3
7 y
8 y
15 y

예제 출력 2

0

예제 입력 3

3
s 0
p 1 y
p 1 z
3
7 y
8 y
10 y

예제 출력 3

5
1 1
1 2
1 2
1 3
1 200

힌트

Below is the time trace for the first example.

출처

ICPC > Regionals > Northern Eurasia > Northwestern Russia Regional Contest > NEERC Northern Subregional 2014 I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /