GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Saturday 16 July 2022

[Solution] DFS Trees Codeforces Solution | Solution Codeforces



E. DFS Trees
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a connected undirected graph consisting of n vertices and m edges. The weight of the i-th edge is i.

Here is a wrong algorithm of finding a minimum spanning tree (MST) of a graph:

vis := an array of length n
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
Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

        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)

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.

Input

The first line of the input contains two integers nm (2n105n1m2105) — the number of vertices and the number of edges in the graph.

Each of the following m lines contains two integers ui and vi (1ui,vinuivi), describing an undirected edge (ui,vi) in the graph. The i-th edge in the input has weight i.

It is guaranteed that the graph is connected and there is at most one edge between any pair of vertices.

Output

You need to output a binary string s, where si=1 if findMST(i) creates an MST, and si=0 otherwise.

No comments:

Post a Comment