The TransCompilator

Solved LeetCode program · 653 of 1,000

#0882 · Reachable Nodes In Subdivided Graph

Hard Graph Theory chunk-14.md

Original English source

Keep a shared starts holding 0, 0, and 1. Keep a shared ends holding 1, 2, and 2. Keep a shared weights holding 10, 1, and 2. Keep a shared distances holding 0, 1000000, and 1000000. Keep a shared visited holding 0, 0, and 0. Keep a shared chosen of 0. Keep a shared closest of 0. Keep a shared partner of 0. Keep a shared candidate of 0.
To choose. Set chosen to -1. Set closest to 1000000.
For every node from 0 to 2.
If item node of visited is 0 and item node of distances is less than closest, set chosen to node, set closest to item node of distances.

To relax. The settled is chosen.
For every edge from 0 to 2.
Set partner to -1. If item edge of starts is settled, set partner to item edge of ends. If item edge of ends is settled, set partner to item edge of starts. Set candidate to item settled of distances plus item edge of weights plus 1. The target is partner. If target is at least 0 and candidate is less than item target of distances, set item target of distances to candidate.

For every round from 1 to 3.
Choose. The here is chosen. If here is at least 0, set item here of visited to 1. Relax.

The total is 3.
For every edge from 0 to 2.
The start is item edge of starts. The finish is item edge of ends. The startroom is 6 minus item start of distances. The finishroom is 6 minus item finish of distances. If startroom is less than 0, set startroom to 0. If finishroom is less than 0, set finishroom to 0. The share is startroom plus finishroom. If share is more than item edge of weights, set share to item edge of weights. Increase total by share.

Show total.

Open in Playground Browse all 1,000 problems

Expected stdout

13