#P4255. 公主の#18文明游戏
公主の#18文明游戏
Description
This game is called “Civil♂ization” (just for laughs), but it’s not the same as the usual meaning.
There are cities in the game, numbered , connected by undirected roads, numbered .
The system may add people to a city , and assign these people the belief .
The system may also cut a road, given by its road ID .
The system may also give a city and ask: among all cities reachable from , if we select people, what is the probability that all of them have belief , modulo .
The input data are not guaranteed to be free of multiple edges and self-loops.
The input data are not guaranteed that the same edge will not be cut more than twice.
Because it is the princess’s game, the input size is large. Please optimize input/output.
Input Format
The first line contains three positive integers .
The next lines each contain two positive integers , representing the initial population and belief of city .
The next lines each contain two positive integers , representing the endpoints of a road.
The next lines each begin with a positive integer .
- If , the system adds people: input three integers .
- If , the system cuts a road: input one integer .
- If , the system asks for a probability: input three integers .
Output Format
For each operation with , output one line with one integer.
5 5 5
5 1
9 2
8 1
8 1
6 2
5 2
1 2
2 2
1 1
5 3
1 1 3 2
2 1
3 3 4 1
3 2 3 1
3 1 2 1
9293681
15578602
849742
Hint
Complaining that someone didn’t tell me I forgot to include a sample.
Supplementing a sample (I actually had one).
Apologies to everyone.
Constraints:
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
- For of the testdata, all beliefs fit within C++ int and Pascal long int.
- For of the testdata, each addition size and each initial population do not exceed .
- For of the testdata, the testdata are randomly generated.
Problem by @玫葵之蝶.
Translated by ChatGPT 5
京公网安备 11011102002149号