luogu#P5188. [COCI 2009/2010 #4] PALACINKE

    ID: 4149 远端评测题 1000ms 32MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2009矩阵加速容斥原理COCI(克罗地亚)

[COCI 2009/2010 #4] PALACINKE

Problem Description

Translated from COCI 2010.02 Task 6 “PALACINKE”.

Anna has some classmates coming over to eat crêpes, but she forgot about it. When she realizes it, she only has TT minutes left to make crêpes. She immediately runs out to buy four ingredients: flour B, eggs J, milk M, and jam P.

Around Anna there are NN intersections, numbered 1N1\ldots N, and MM directed roads connecting them. For each road, we know which ingredients are sold in the shop on that road. It is guaranteed that the shop on every road sells at least one of the four ingredients above.

When Anna travels along a road, if she enters the shop on that road to buy something, then it takes her 22 minutes to pass that road; otherwise, it takes 11 minute. Even after she has already bought all ingredients, she may still enter shops to buy things.

Anna must start from node 11 and finally return to node 11.

Anna needs to obtain all four ingredients within TT minutes. Compute how many “shopping plans” she has, modulo 55575557. A shopping plan includes the order of nodes she visits, and for each road whether she buys ingredients or not, but it does not consider what exactly she buys in which shop. For example, when T=7T=7, in the figure above there are 55 shopping plans:

Input Format

The first line: N,MN, M.
The next MM lines: each line contains two integers u,vu, v and a string ss consisting only of characters BJMP. Here, u,vu, v describe a directed road, and ss indicates which ingredients are sold in the shop on that road. It is guaranteed that no two directed roads are identical (but there may be two roads connecting the same pair of nodes with opposite directions).
Line N+2N+2: TT.

Output Format

One line with one integer, the number of shopping plans Anna has.

3 3
1 2 BMJ
2 3 MJP
3 1 JPB
5
3
3 4
1 2 B
2 1 P
1 3 J
3 1 M
8
2
5 7
1 2 B
2 4 M
1 3 J
3 4 MB
4 1 JP
4 5 J
5 1 P
7
5

Hint

Constraints: 1N251\le N\le 25, 1M5001\le M\le 500, 1T1091\le T\le 10^9.
It is guaranteed that no two directed roads are identical (but there may be two roads connecting the same pair of nodes with opposite directions).

Translated by ChatGPT 5