[Solution] DFS Trees Codeforces Solution | Solution Codeforces
You are given a connected undirected graph consisting of vertices and edges. The weight of the -th edge is .
Here is a wrong algorithm of finding a minimum spanning tree (MST) of a graph:
s := a set of edges
function dfs(u):
vis[u] := true
iterate through each edge (u, v) in the order from smallest to largest edge weight
if vis[v] = false
add edge (u, v) into the set (s)
dfs(v)
function findMST(u):
reset all elements of (vis) to false
reset the edge set (s) to empty
dfs(u)
Difference Operations Codeforces Solution
Difference of GCDs Codeforces Solution
Doremy's IQ Codeforces Solution
Difference Array Solution Codeforces
Partial Virtual Trees Codeforces Solution
Each of the calls findMST(1), findMST(2), ..., findMST(n) gives you a spanning tree of the graph. Determine which of these trees are minimum spanning trees.
The first line of the input contains two integers , (, ) — the number of vertices and the number of edges in the graph.
Each of the following lines contains two integers and (, ), describing an undirected edge in the graph. The -th edge in the input has weight .
It is guaranteed that the graph is connected and there is at most one edge between any pair of vertices.
You need to output a binary string , where if findMST(i) creates an MST, and otherwise.
No comments:
Post a Comment