Orig Description
Problem H: Winter Bells
The best night ever in the world has come! It's 8 p.m. of December 24th, yes, the night of Cristmas Eve. Santa Clause comes to a silent city with ringing bells. Overtaking north wind, from a sleigh a reindeer pulls she shoot presents to soxes hanged near windows for children.
The sleigh she is on departs from a big christmas tree on the fringe of the city. Miracle power that the christmas tree spread over the sky like a web and form a paths that the sleigh can go on. Since the paths with thicker miracle power is easier to go, these paths can be expressed as undirected weighted graph.
Derivering the present is very strict about time. When it begins dawning the miracle power rapidly weakens and Santa Clause can not continue derivering any more. Her pride as a Santa Clause never excuses such a thing, so she have to finish derivering before dawning.
The sleigh a reindeer pulls departs from christmas tree (which corresponds to 0th node), and go across the city to the opposite fringe (n-1 th node) along the shortest path. Santa Clause create presents from the miracle power and shoot them from the sleigh the reindeer pulls at his full power. If there are two or more shortest paths, the reindeer selects one of all shortest paths with equal probability and go along it.
By the way, in this city there are p children that wish to see Santa Clause and are looking up the starlit sky from their home. Above the i-th child's home there is a cross point of the miracle power that corresponds to c[i]-th node of the graph. The child can see Santa Clause if (and only if) Santa Clause go through the node.
Please find the probability that each child can see Santa Clause.
Input
Input consists of several datasets.
The first line of each dataset contains three integers n, m, p, which means the number of nodes and edges of the graph, and the number of the children. Each node are numbered 0 to n-1.
Following m lines contains information about edges. Each line has three integers. The first two integers means nodes on two endpoints of the edge. The third one is weight of the edge.
Next p lines represent c[i] respectively.
Input terminates when n = m = p = 0.
Output
For each dataset, output p decimal values in same order as input. Write a blank line after that.
You may output any number of digit and may contain an error less than 1.0e-6.
Constraints
3 ≤ n ≤ 100
There are no parallel edges and a edge whose end points are identical.
0 < weight of the edge < 10000
Sample Input
3 2 1
0 1 2
1 2 3
1
4 5 2
0 1 1
0 2 1
1 2 1
1 3 1
2 3 1
1
2
0 0 0
Output for the Sample Input
1.00000000
0.50000000
0.50000000
Extracted Specification
An integer n (3 ≤ n ≤ 100), representing the number of nodes in a graph.
An integer m, representing the number of edges in the graph.
An integer p, representing the number of special nodes.
m lines follow with three integers each, representing two nodes and the weight of an edge connecting them. (0 < weight < 10000)
p lines follow with an integer each, representing a special node.
Input terminates when n = m = p = 0.
### Example Input:
```
3 2 1
0 1 2
1 2 3
1
4 5 2
0 1 1
0 2 1
1 2 1
1 3 1
2 3 1
1
2
0 0 0
```
### Function Signature:
Write a function f(inputs) that takes in the input.
def f(inputs: List[Tuple[int, int, int, List[Tuple[int, int, int]], List[int]]]):
'''
inputs: a list of tuples, where each tuple contains:
- an integer
- an integer
- an integer
- a list of tuples, each containing three integers
- a list of integers
'''
Test Case Generator
To generate test cases for the problem "Winter Bells," we need to create a generator that produces random valid inputs fitting the problem's constraints. Here's a Python function to generate such test cases:
```python
import random
def generate_test_case():
# Constraints
max_n = 100
max_m = max_n * (max_n - 1) // 2 # Maximum edges in a complete graph
max_weight = 9999
max_p = 100
# Randomly choose n, m, p
n = random.randint(3, max_n) # Number of nodes
m = random.randint(n-1, min(max_m, n * (n - 1) // 2)) # Number of edges
p = random.randint(1, max_p) # Number of children
edges = set()
# Generate a connected graph
for i in range(1, n):
u = i
v = random.randint(0, i - 1)
weight = random.randint(1, max_weight)
edges.add((u, v, weight))
# Add additional edges to make it more complex
while len(edges) < m:
u = random.randint(0, n - 1)
v = random.randint(0, n - 1)
if u != v:
weight = random.randint(1, max_weight)
edges.add((u, v, weight))
edges = list(edges)
children_nodes = [random.randint(0, n - 1) for _ in range(p)]
# Transform to the required output format
input_data = f"{n} {m} {p}\n"
input_data += "\n".join(f"{u} {v} {weight}" for u, v, weight in edges) + "\n"
input_data += "\n".join(str(c) for c in children_nodes) + "\n"
return input_data
def generate_multiple_test_cases(number_of_cases):
test_cases = []
for _ in range(number_of_cases):
test_cases.append(generate_test_case())
return test_cases
# Example usage
if __name__ == "__main__":
random.seed(42) # For reproducibility
num_cases = 5
test_cases = generate_multiple_test_cases(num_cases)
for i, test_case in enumerate(test_cases):
print(f"Test case {i+1}:")
print(test_case)
print()
```
This function:
1. Generates a random number of nodes (`n`) between 3 and 100.
2. Ensures at least `n-1` edges to keep the graph connected and generates up to `min(max_m, n * (n - 1) // 2)` edges.
3. Randomly selects the number of children (`p`).
4. Creates a connected graph by adding edges such that every node is reachable.
5. Ensures no duplicate edges and no self-loops.
6. Randomly assigns children nodes from the graph nodes.
7. Formats the test case according to the specified input format.
The `generate_multiple_test_cases` function can generate multiple test cases and is useful for batch testing.
Make sure to adjust `random.seed()` or remove it if you want different outputs each time you run the generator.
Extract Arguments
def extract_arguments(fh):
datasets = []
while True:
n, m, p = map(int, fh.readline().strip().split())
if n == 0 and m == 0 and p == 0:
break
edges = [tuple(map(int, fh.readline().strip().split())) for _ in range(m)]
children_nodes = [int(fh.readline().strip()) for _ in range(p)]
datasets.append((n, m, p, edges, children_nodes))
return datasets
# Example usage
# with open('input.txt', 'r') as fh:
# data = extract_arguments(fh)