Many Many Cycles
Time limit2sMemory limit2048 MB
Given a weighted undirected graph, find the largest d that divides the length of every simple cycle, or 0 if no such d exists.
- Level
Medium7 of 10
- Topics
- Graph, DFS, Number theory
- Solved
- No attempts yet
Problem
Consider an undirected graph . Find the maximal number such that the lengths of all simple cycles are divisible by . If there is no such number, output .
Input
The first line contains two integers and , the number of vertices and edges (, ). Each of the next lines contains three integers , , and , which mean that there is a bidirectional edge between vertices and with length (, ). The graph has no loops or multiple edges.
Output
Print one integer: the answer to the problem.