#P4489. [CTSC2009] 纷繁世界
[CTSC2009] 纷繁世界
Description
For simplicity, assume there are people and types of events. Define a binary relation “related” between event types:
- The relation is binary, meaning we only determine whether two types of events are related.
- Events of the same type are always related.
- If event is related to event , then event is also related to event .
Let be the sequence of events person plans to complete (called the plan sequence), where is the length of . Each event is one of the event types, and events of the same type may occur multiple times.
As time goes by, each event in every plan sequence will occur exactly once, and no two events occur at the same moment.
To describe the order in which events occur, define $P = (Q_{i_1, j_1}, Q_{i_2, j_2}, \cdots, Q_{i_l, j_l})$ as a development trajectory of the world. is an ordered sequence satisfying:
- For every person, each event in their plan sequence appears in exactly once.
- For any two events and belonging to the same plan sequence (), must occur before (i.e., appear earlier in ).
Two trajectories and are defined to be essentially different if and only if there exist two related events and whose relative order differs in and . In other words, if in the event occurs before while in the event occurs after , then and are essentially different; similarly, if in occurs after but in it occurs before , then and are also essentially different.
Note: “Essentially the same” is transitive. That is, if is essentially the same as , and is essentially the same as , then is necessarily essentially the same as .
Given , , each person’s plan sequence, and the relatedness between event types, compute how many essentially different world development trajectories there are.
Input Format
- The first line contains an integer denoting the number of people .
- The second line contains an integer denoting the number of event types . All event types are numbered from to .
- Then, for each person , the description of their plan sequence is given:
- The first line contains one integer, the sequence length .
- The second line contains integers, giving each event in in order.
- Finally, lines follow, containing an matrix dep that describes the relatedness. Each line contains integers, each being or . dep(i, j) denotes the integer in the -th row (from top to bottom) and the -th column (from left to right). If dep(i, j) equals , then event type and event type are related; otherwise, they are unrelated.
Output Format
Output a single line containing one integer, the number of essentially different world trajectories.
2
3
2
0
1
2
2
1
1 1 0
1 1 1
0 1 1
4
Hint
Sample Explanation
There are people and event types, with . , , , .
There are different development trajectories:
- ;
- ;
- ;
- .
Any other valid development trajectory is necessarily essentially the same as one of these four. For example, is essentially the same as , because the two trajectories only swap the order of and , and those two event types are unrelated.
Constraints
For of the testdata: , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号