Not able to get the approch

Hello

I am trying to solve this question from hackerearth…

Here after finding the bridge …
How should we calculate the number of nodes on each side of edge.
This is the code i have written for finding edge…

Thanks

Hey @ashishnnnnn
Once u find the edge then u can apply bfs/dfs on both its adjacent vertices to count the no of edges on each side
Make sure u are not using the edge during dfs/bfs which u are considering to be critical

Hiii…

I have done the steps as per you suggested…
What i have done is…
First i have stored the edges vertex as pair in vector.
Now for every vertex i have called dfs marking the other vertex as visited.
This is the code…
https://www.hackerearth.com/submission/52030695/

It is showing wrong answer and TLe…
What is wrong in the logic… TLE we will consider later…

Hey @ashishnnnnn
Yes I van understand u may TLE by this method
For efficient method refer to editorial

U are getting WA because u are not checking if connected component increases or not

Hii…
I as per the definition of bridge… the connected component will automatically increase.
I have learnt this algorithm to find the bridge from codeNcode youtube channel.

In the editorial they have written the code without any explanation.
I am not able to understand that one… :slight_smile:

Hey @ashishnnnnn

Hii…
Thank you very much…

I got each and every line…
Thanks…
I wish each editorial of hackerearth could be like that…
:slight_smile:

1 Like

One thing i want to ask…

Recently i have started practising question of graph…Like DFS,BFS,DSU

I have chosen hackerearth for this and started practising from easy section.

But i found the in easy tag they have given hard question and also most of the question have only have code as editorial.

1).Does questions of graph on hackearth is really tough or it is happening because of 1st time.
2). Should i practice graph questions from somewhere else… or hackerearth is good platform as it has question topic wise.

Thanks

HackerEarth is competitive programming platform
So questions are of CP and not normal DSA ,so u will find this much difficulty

Prefer a platform with good editorials
Codechef have detailed editorials
Nowdays u can find codeforces video editorials as well for recent contests
I don’t know about the rest

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.