K-Divisible Graph
Time limit2sMemory limit1024 MB
Given a weighted undirected graph and K, decide whether every closed walk has total weight divisible by K.
- Level
Medium6 of 10
- Topics
- Graph, Union-find, Math
- Solved
- No attempts yet
Problem
A weighted undirected graph is called a -divisible graph if, for every closed walk in the graph, the sum of the edge weights along is always a multiple of . If an edge is used several times, its weight is added to the sum once for each use.
Given a weighted undirected graph and a positive integer , determine whether is a -divisible graph.
Input
The first line contains the number of vertices , the number of edges , and the positive integer , separated by spaces. (, , )
Each of the next lines contains three integers , , and , separated by spaces. This describes an undirected edge with weight between vertex and vertex . (, )
There can be several edges between the same pair of vertices, and an edge may connect a vertex to itself. The graph may not be connected.
Output
If the given graph is a -divisible graph, print Yes. Otherwise, print No.
Hint
A closed walk is a walk that starts and ends at the same vertex. It may visit the same vertices and edges several times.