#P8456. 「SWTR-8」地地铁铁
「SWTR-8」地地铁铁
Background
D_T_ : D_tt : ddT_ : ddtt = 9 : 3 : 3 : 1.
Problem Description
You are given an undirected connected graph with vertices and edges. Each edge is labeled D or d.
Define an unordered pair of vertices to be "Iron" if and only if and there exists a simple path between and on which both D and d appear.
A knows the importance of the law of independent assortment DdTt, so he asks you to count such vertex pairs.
Notes:
- A simple path is a path that does not pass through any repeated vertex.
- The graph is guaranteed to have no self-loops, and it may contain multiple edges.
Input Format
The first line contains an integer , indicating the Subtask ID of this test point.
The second line contains two integers .
The next lines each contain two integers and a letter , meaning there is an undirected edge connecting and labeled .
Output Format
Output one integer in one line, representing the answer.
0
8 13
1 2 d
1 3 d
2 3 d
3 4 d
3 5 D
4 5 d
4 6 d
5 6 D
6 7 d
6 8 d
6 8 D
6 8 D
7 8 d
24
Hint
Constraints and Conventions
This problem uses bundled testdata.
- Subtask #1 (6 points): , .
- Subtask #2 (16 points): , . Depends on Subtask #1.
- Subtask #3 (17 points): .
- Subtask #4 (18 points): .
- Subtask #5 (19 points): , . Depends on Subtask #2.
- Subtask #6 (24 points): No special limits. Depends on Subtask #3, #4, #5.
For of the data:
- , .
- .
- .
- The graph is guaranteed to have no self-loops, and it may contain multiple edges.
Help and Tips
Please pay attention to I/O optimization.
Source
- Sweet Round 8 E.
- Idea & Solution: Alex_Wei.
- Tester: asmend.
Translated by ChatGPT 5