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

    ID: 3020 远端评测题 1000ms 1000MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP图论O2优化枚举最短路Code+

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

Background

Recently, PlayerUnknown’s Battlegrounds (PUBG) has taken the world by storm. Pipi and Maomao have become obsessed with the game and often team up to play.

In the game, their favorite tactic is camping at bridges, where they can often secure lots of loot when the timing is right.

Of course, sometimes camping a bridge isn’t possible, so Pipi and Maomao will instead camp on other chokepoints.

Dr. K, being older and having a heart condition, naturally can’t play this game, but that doesn’t stop him from doing some theoretical analysis. Lately, he has been very interested in Pipi and Maomao’s tactics.

Problem 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