NOI Contest Archive

Archive / 2026 / Final Round — Day 2

The Cyber Heist

Medium · noi-2026-day-2

A legendary data runner, “Cipher,” is attempting to extract a highly sensitive file from the heavily fortified MegaCorp network. The network consists of various servers connected by two-way data streams. Cipher needs to route their connection from their personal terminal (node \(S\)) to the central mainframe (node \(W\)) where the file is stored.

Each data stream has a base traversal time required to bypass its standard encryption and route the packets.

However, MegaCorp has deployed hidden Intrusion Detection Systems (IDS) on specific servers, known as “watchtower nodes”. If Cipher’s connection routes through any watchtower node, the network’s active defense protocols are triggered, putting the system on high alert. Once the network is on high alert, the encryption overhead is massively increased, and the traversal time for all subsequent data streams Cipher crosses is doubled.

Your task is to calculate the minimum total time required for Cipher to route their connection from their starting terminal (node \(S\)) to the mainframe (node \(W\)), taking into account the watchtower nodes and their effect on traversal times.

Input Format

Output Format

Output a single integer — the minimum total time required for Cipher to reach the mainframe \(W\) from the starting node \(S\).

Constraints

Sample Input 0

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

Sample Output 0

12