#P9504. 『MGOI』Simple Round I | C. 魔法禁林

    ID: 10531 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>图论洛谷原创O2优化记忆化搜索

『MGOI』Simple Round I | C. 魔法禁林

Background

The meaning of battle is to survive. In this highly competitive world, only by becoming stronger can you survive. — Hall Magician S.

Problem Description

On the first day of school, Little M cannot wait to plan a trip to the mysterious Forbidden Forest.

Little M has two important attributes: mana and health. Very specially, at the beginning, these two values can be chosen arbitrarily by Little M.

The Forbidden Forest can be seen as an undirected simple connected graph with nn vertices and mm edges. Little M will walk in the forest, from the start vertex ss to tt.

Each time he traverses an edge, Little M’s mana decreases by 11. At the same time, there is a magical beast with an attack attribute on each edge, and Little M must fight it. If Little M’s mana before traversing this edge is kk, and the beast’s attack on this edge is ww, then the battle that happens while traversing this edge will consume wk\left\lfloor \dfrac{w}{k} \right\rfloor health. The beast will not be defeated, so if the same edge is traversed multiple times, a battle will happen every time.

Little M must ensure that when his mana is fully used up, his health is 00, and at that moment he has arrived at vertex tt.

You need to find the minimum initial health Little M needs.

Input Format

The first line contains four integers n,m,s,tn, m, s, t.

The next mm lines each contain three integers u,v,wu, v, w, indicating that there is an edge between vertices u,vu, v, and the beast’s attack on this edge is ww.

Output Format

Output one integer in one line, representing the minimum initial health Little M needs.

3 3 1 3
1 2 2
1 3 5
3 2 3
4
5 10 1 5
2 1 3
3 1 7
4 2 4
5 3 9
5 1 7
2 3 2
5 4 6
1 4 10
5 2 5
3 4 10
6

Hint

[Sample 1 Explanation]

At the beginning, Little M chooses mana 22 and health 44.

  • 121\rightarrow2: mana left 11, health left 422=34 - \left\lfloor \frac{2}{2} \right\rfloor=3.
  • 232\rightarrow3: mana left 00, health left 331=03 - \left\lfloor \frac{3}{1} \right\rfloor=0.

It can be proven that 44 is the minimum initial health Little M needs.

[Constraints]

This problem uses bundled Subtask testdata.

For all testdata, 1n200001 \le n \le 20000, 1m400001 \le m \le 40000, 1s,t,u,vn1\le s,t,u,v\le n, sts\ne t, the graph is an undirected simple connected graph, and 0w1000\le w\le 100.

Subtask nn mm ww\le Score
11 55 1010 1010 1111
22 20002000 40004000 2727
33 2000020000 4000040000 11 1919
44 100100 4343

Translated by ChatGPT 5