Spy Network
Time limit2sMemory limit256 MB
Values spread along directed edges by repeated gcd updates until stable, and you count how many employees end at L.
- Level
Medium7 of 10
- Topics
- Graph, Topological sort, Number theory
- Solved
- No attempts yet
Problem
In a directed spy network, each employee holds an integer information value. When employee a sends to b, employee b replaces their value with gcd(received, old). Propagation continues until stable. Count how many employees end with the leaked value .
Input
The first line contains the number of test cases. Each test case gives , , , then directed edges and initial values.
Output
For each test case, print how many employees hold value in the final stable state.