Snowball Fight 1
Time limit2sMemory limit1024 MB
Given a weighted graph with L countries starting at fixed nodes, find which pairs of countries end up fighting as their fighters spread.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, Simulation
- Solved
- No attempts yet
Problem
An undirected, weighted graph with nodes is given. During IOI, countries have a snowball fight. At the start, each country has a fort at one node.
At time , every country starts sending out fighters. The fight follows these rules:
- If a country owns a fort, its fighters leave the fort along every edge from it, all at the same speed.
- If two countries meet along an edge, both stop and fight forever.
- If two countries meet at a node, both stop and fight forever.
- If a country reaches a node where countries are already fighting, it joins that fight.
- If a country reaches a node before any other country, it builds a fort at that node and sends fighters out along the edges from the node by rule 1.
A node holds at most one fort. If two countries reach a node at the same time, the fighters who arrived there stop and fight there forever without moving on.
Determine which pairs of countries will fight each other.
Input
The first line contains three integers (, , ): the number of nodes, countries, and edges. The next lines each contain the node where a country starts. The next lines each contain three integers (, , ), meaning there is an undirected edge of length between nodes and . Nodes are numbered from 0. There is at most one edge between any pair of nodes, and no two countries start on the same node.
Output
For each pair of countries that fight, print a line a b with . Countries are numbered from 0. Print the pairs sorted by the first index. For example, if and all three countries fight, the output is:
0 1
0 2
1 2