#C2321. Connect the Graph

    ID: 45625 Type: Default 1000ms 256MiB

Connect the Graph

Connect the Graph

You are given an undirected weighted graph with \( n \) nodes and \( m \) edges. The nodes are numbered from 1 to \( n \). Each edge is represented by three integers \( u \), \( v \) and \( w \) where \( u \) and \( v \) are the endpoints of the edge and \( w \) is its weight.

Your task is to determine whether the graph is connected by using only the existing edges. In this problem, if the graph is already connected then no additional edge is needed and you should output 0. Otherwise, output No to indicate that it is impossible to connect the graph under the given constraints.

Note: Even though the problem statement discusses the minimum total weight of the new edges required to connect the graph, the only permitted operation is to check the connectivity using the given edges. Hence, if the graph is disconnected, simply output No instead of calculating any additional weight.

Formula: A graph is connected if for every vertex \( v \), there exists a path from vertex 1 to \( v \). That is, \( \forall v \in \{1,2,...,n\}, \, dist(1, v) < \infty \).

inputFormat

The input is read from standard input and has the following format:

n m
u1 v1 w1
u2 v2 w2
...\num vm wm

Here, the first line contains two integers \( n \) and \( m \) representing the number of nodes and edges respectively. Each of the next \( m \) lines contains three integers \( u \), \( v \) and \( w \), indicating an edge between nodes \( u \) and \( v \) with weight \( w \).

outputFormat

If the graph is connected using only the given edges, output 0. Otherwise, output No.

The output should be written to the standard output.

## sample
4 3
1 2 1
2 3 2
3 4 3
0