#P7846. 「dWoi R2」Arcade hall / 街机厅
「dWoi R2」Arcade hall / 街机厅
Description
The country of Yaoyao-Yaoyao-Ba-Yiling has cities. They are connected by a magical communication tool — the “Senpai Talisman”. The Senpai Talisman of the -th city is engraved with a positive integer . There are roads among these cities. The -th road connects city and city , and has an attribute . This road is denoted as , where , meaning:
- When , city and city are in an antagonistic relationship.
- When , city and city are in an equal relationship.
- When , city and city are in a friendly relationship.
Each road is bidirectional, and it is guaranteed that any two cities are mutually reachable.
Recently, Mars has suffered from the MARS-514 virus outbreak, so the construction of the Senpai Talisman system must be accelerated. We define:
- , and is a positive integer.
- For a road , the following requirements must be satisfied:
- When , i.e., city and city are antagonistic, it must hold that .
- When , i.e., city and city are friendly, it must hold that .
- When , i.e., city and city are equal, there is no requirement on the relationship between and .
After assigning values to , treat as a sequence. Determine how many essentially different sequences can be formed.
In addition, the ruler of Yaoyao-Yaoyao-Ba-Yiling, Haoer Jiejie, found that the larger is, the more ink is needed, and the harder it is to build. Therefore, Haoer Jiejie wants to know the minimum possible value of the sum of .
Note that, in this problem, sequences and are essentially the same if and only if for all , .
“Essentially different” means two sequences that are not essentially the same.
Brief statement:
- There is a tree with nodes. Node has a node weight , and edge has an edge weight .
- For each edge , the endpoint node weights must satisfy:
- , .
- , no requirement.
- , .
- For any node weight, .
- When is treated as a sequence, find (1) the number of essentially different sequences , and (2) the minimum possible sum of .
Input Format
The first line contains two integers , representing the number of cities and the value range.
The next lines each contain three integers , describing a road.
Output Format
Output one line with two integers: the number of essentially different sequences that satisfy the requirements, and the minimum possible sum of .
If there is no essentially different sequence (i.e., the answer to the first question is ), then output for the second question as well.
Only the first answer is taken modulo .
3 3
1 2 0
1 3 0
12 4
9 3
1 2 0
1 3 1
1 4 1
2 5 2
2 6 1
6 7 0
4 8 2
4 9 0
648 12
Hint
Explanation for Sample 1
The roads in the sample are distributed as follows:

There are assignment methods in total:
- .
- .
- .
- .
- , this is the optimal case.
- .
- .
- .
- .
- .
- .
- .
Explanation for Sample 2
The roads in the sample are distributed as follows:

For the second question, one optimal assignment is: .
Constraints and Notes
This problem uses bundled testdata.
- Subtask 1 (5 pts): or .
- Subtask 2 (5 pts): .
- Subtask 3 (10 pts): , .
- Subtask 4 (20 pts): .
- Subtask 5 (10 pts): , .
- Subtask 6 (50 pts): no special constraints.
For of the testdata, , .
For Subtask 1 ~ 5, .
In the subtask descriptions above, means that for all , .
For Subtask 1, “or” means that part of the test points in Subtask 1 satisfy , and the other part satisfy .
Translated by ChatGPT 5
京公网安备 11011102002149号