#P6038. 「ACOI2020」惊吓路径
「ACOI2020」惊吓路径
Description
Koro-sensei told them that the cave can be approximately seen as an out-tree with nodes. Due to the terrain, the edge from one node to another has a direction, and the directions of all edges are consistent. The root of this tree is the node with in-degree . Each node has a scare value; the scare value of node is .
Koro-sensei told them that there are many scare paths in this cave. If the path formed by two nodes is a scare path, then it satisfies:
- must be in the subtree of .
- The bitwise OR of the scare values of all nodes on the path from to is .
Walking through a scare path will earn a “surprise gift” from Koro-sensei. Koro-sensei has prepared the gifts in advance, but Karma already knows Koro-sensei has some improper intentions, not to mention the number of gifts might not be enough. Koro-sensei promised that there would be as many surprise gifts as there are scare paths. Karma has learned, through some mysterious means, how many surprise gifts Koro-sensei prepared. Now he wants to know how many scare paths there are, i.e., the minimum number of gifts Koro-sensei must prepare. If it is not enough, he will expose Koro-sensei’s intentions. Of course, Karma wants to take advantage of this and mess with Koro-sensei. So he cheated got Koro-sensei’s map in advance, and wants to ask: how many scare paths are there in this graph?
Input Format
The first line contains two integers .
The second line contains integers, representing the scare value of each node.
The next lines each contain two integers , indicating that there is a directed edge between nodes and , and node can reach node . Node cannot reach node .
Output Format
Output one integer in one line, representing the number of scare paths in this cave.
5 10
5 9 6 4 2
3 1
3 4
1 2
1 5
2
7 5
6 7 4 5 7 8 9
1 2
2 3
2 4
1 5
5 6
5 7
16
8 5
4 3 2 5 6 7 6 2
1 2
1 5
2 3
2 4
5 6
5 7
6 8
16
Hint
Sample Explanation #1

Only two paths satisfy the conditions:
- . The bitwise OR of the scare values of all nodes on this path is .
- . The bitwise OR of the scare values of all nodes on this path is .
Constraints
This problem uses bundled testdata.
- Subtask 1 (10 points): , .
- Subtask 2 (30 points): For any edge, , , .
- Subtask 3 (20 points): , .
- Subtask 4 (40 points): , .
For of the testdata: , .
Note
In the fourth subtask, the memory limit is 256MB; in the other subtasks, the memory limit is 128MB.
Translated by ChatGPT 5
京公网安备 11011102002149号