#P4061. [Code+#1] 大吉大利,晚上吃鸡!

    ID: 3002 远端评测题 1000ms 1000MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp图论O2优化枚举,暴力最短路概率论,统计

[Code+#1] 大吉大利,晚上吃鸡!

Description

The game map can be abstracted as an undirected graph with nn nodes and mm edges, numbered from 11 to nn. Each edge has a positive integer length.

Assume the “Da Mowang” will start from SS and reach TT (both SS and TT are known), and will only take shortest paths. Pipi and Maomao will ambush at points AA and BB.

To ensure they can always ambush the Da Mowang while still leaving him a way out, AA and BB must satisfy:

  • Among all possible shortest paths, the Da Mowang must pass through at least one of AA or BB.
  • Among all possible shortest paths, there does not exist a path that passes through both AA and BB.

Dr. K wants to know how many pairs (A,B)(A, B) satisfy the two conditions above. Swapping AA and BB counts as the same plan.

Input Format

The first line contains four integers n,m,S,Tn, m, S, T $(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 mm lines each contain three integers u,v,wu, v, w (1u,vn,1w109)(1 \le u, v \le n, 1 \le w \le 10^{9}), indicating there is an edge of length ww connecting uu and vv.

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 <2,3>,<2,4>,<4,3>,<4,5>,<6,3>,<6,5><2,3>,<2,4>,<4,3>,<4,5>,<6,3>,<6,5>.

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