| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 22 | 11 | 9 | 47.368% |
There are N cities in Bitlandia. Some cities are connected by train or bus, and connections work both ways. Marijonas is preparing for a month-long vacation in Bitlandia. He wants to use trains as much as possible, so he bought a monthly railway ticket. This ticket allows Marijonas unlimited train travel for a month, but it does not cover the cost of bus trips.
Marijonas wants to stay in one city - but is not yet sure in which one. Marijonas would like to stay in a city which allows for a cheap travel to all other cities, because he intends to travel to some of them while staying in the chosen city.
For Marijonas, going from one city to another is cheap if there is a route on which he travels on an unlimited number of trains and at most one bus.
Calculate the number of Bitlandia cities Marijonas could stay in.
Two numbers are given in the first line: the number of cities N, and the number of connections between two cities M. Cities are labeled by 1 up to N, inclusive.
Each of the next M lines consist of two numbers, ai and bi, and a character Ti. The i-th connection connects cities ai and bi, while the character Ti indicates the transportation type of the connection: if Ti is T, then the i-th connection is by train, and if Ti is A, it is by bus.
Output a single integer – the number of cities Marijonas could stay in.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 10 | There are no bus connections |
| 2 | 6 | There are no train connections |
| 3 | 30 | N ≤ 1 000, M ≤ 20 000 |
| 4 | 35 | N ≤ 20 000 |
| 5 | 19 | No additional constraints |
5 5 3 1 A 3 5 A 4 5 T 2 3 T 2 1 A
2
Marijonas could stay cities 2 or 3.
Train connections are marked by continuous lines, and bus connections by dotted lines.
7 8 7 5 A 3 7 A 3 1 A 3 4 T 3 5 A 7 1 A 5 6 T 2 7 T
4
All cities can be visited cheaply from cities 2, 3, 4 and 7.
Olympiad > Lithuanian Olympiad in Informatics > Lithuanian Olympiad in Informatics 2017/2018 > National Round (2) > 7-9 Classes ?번
Olympiad > Lithuanian Olympiad in Informatics > Lithuanian Olympiad in Informatics 2017/2018 > National Round (2) > 10-12 Classes ?번