#P4061. [Code+#1] 大吉大利,晚上吃鸡!
[Code+#1] 大吉大利,晚上吃鸡!
Description
The game map can be abstracted as an undirected graph with nodes and edges, numbered from to . Each edge has a positive integer length.
Assume the “Da Mowang” will start from and reach (both and are known), and will only take shortest paths. Pipi and Maomao will ambush at points and .
To ensure they can always ambush the Da Mowang while still leaving him a way out, and must satisfy:
- Among all possible shortest paths, the Da Mowang must pass through at least one of or .
- Among all possible shortest paths, there does not exist a path that passes through both and .
Dr. K wants to know how many pairs satisfy the two conditions above. Swapping and counts as the same plan.
Input Format
The first line contains four integers $(1 \le n \le 5 \times 10^{4}, 1 \le m \le 5 \times 10^{4}, 1 \le S, T \le n)$, as described above.
The next lines each contain three integers , indicating there is an edge of length connecting and .
Output Format
Output a single line containing the answer.
7 7 1 7
1 2 2
2 4 2
4 6 2
6 7 2
1 3 2
3 5 4
5 7 2
6
5 5 1 4
1 2 1
1 3 1
2 4 1
3 4 1
4 5 1
3
6 7 1 4
1 2 1
1 3 1
2 4 1
3 4 1
4 5 1
1 6 2
6 4 2
5
Hint
Explanation for Sample 1:
The valid pairs are .

From CodePlus November 2017, proudly presented by the Tsinghua University Student Association of Computer Science and Technology Algorithms and Programming Contest.
Credit: idea/Chen Yu, problem setting/Chen Yu, verification/Xing Jiankai.
Git Repo: https://git.thusaac.org/publish/CodePlus201711
Thanks to Tencent for supporting this contest.
Translated by ChatGPT 5
京公网安备 11011102002149号