Nộp bài | Các bài nộp | Làm tốt nhất | Về danh sách bài |
HWAYADS - Highway Advertising |
English | Tiếng Việt |
After several years of preparing, Vietnam has been chosen to organize the IOI2023, it's such a big even with Vietnamese fans of informatics! The host country wants to invite all guests to visit N famous places (numbered 0..N-1). Of course the journey will start from the capital Hanoi (numbered 0). And after many years of developing, the travel system has been so modern that it needs only exactly N-1 highways for guests to travel to all N places from the capital. It's not only that but Ministry of Culture and Information also has an idea to paint some slogans on the highways to advertise Vietnam and the IOI competition. KTuan wants to watch the competition so he came back to Vietnam early. On the days in Hanoi, KTuan met AnhDQ (an old friend) by chance. Hearing that exciting idea, KTuan has a slogan in his mind and wants to ask AnhDQ: how many times it appears on the way from Hanoi to the places?. Please help AnhDQ answer KTuan's question!
Input
- The first line contains N.
- N-1 following lines, each line contains two number u, v and the string S, showing a highway from u to v, on which is painted the string S directed u->v.
- The last line contains KTuan's slogan.
Output
- The answer of AnhDQ.
Example
Input:
11
0 2 Welcom
0 7 VietN
2 8 nauTK
7 3 am
7 9 nauTK
2 5 eKTuan
5 4 IOIKTuanIO
7 1 IOI
5 6 IOI23
4 10 I2023
KTuanIOI
Output:
3
*** Explaination:
On the way 0-2-5-6: WelcomeKTuanIOI23
On the way 0-2-5-4-10: WelcomeKTuanIOIKTuanIOI2023
Limitations
- N ≤ 17032.
- The length of the strings ≤ 1000.
- The length of KTuan's slogan ≤ 70.
Sorry for my bad English!^_^ Please comment for a better translation ;)
Được gửi lên bởi: | AnhDQ |
Ngày: | 2009-05-06 |
Thời gian chạy: | 0.200s |
Giới hạn mã nguồn: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Ngôn ngữ cho phép: | Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET |
Nguồn bài: | AnhDQ (re-covered) |
hide comments
2017-12-14 04:46:54
Last edit: 2020-08-31 17:58:21 |
|
2013-08-05 16:24:46 Chuyên Triết Tổng Hợp
hash =)) Last edit: 2013-08-05 16:25:01 |
|
2009-05-08 05:00:07 Nguyễn Mai Lan
Well, KMP on tree is enough :D Don't need to use DP :) |
|
2009-05-07 17:44:48 Race with time
By the way, spelling mistake: "KTuan has a slogan in his mine" -> "his mind" [AnhDQ]: thx, i corrected it Last edit: 2009-05-08 04:33:50 |
|
2009-05-07 17:15:20 Race with time
Thanks! Replacing "<=" by "<" made it get 80 points. I'm considering the way to improve the DP. Anyway, I keep my opinion that 1s is quite strict for this problem. Last edit: 2009-05-07 17:15:49 |
|
2009-05-07 15:42:39 AnhDQ
KMP works well, sure ;) your 2375755 submit has 2 TLE tests only, but WA some ^^ |
|
2009-05-07 09:19:38 Race with time
Time limit is somewhat strict. :) I think 2-3s is reasonable :? Last edit: 2009-05-07 09:20:43 |
|
2009-05-07 06:13:43 Race with time
KMP + DP on tree :? |