Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Same code is giving runtime and time limited exceeded error if vector is not defined globally in CSES graph algorithms problem Counting Rooms

Hello I am trying to solve simple graph algorithms problem counting room. In this problem I am getting runtime and time limit exceeded if vector is not defined globally. Can someone tell why this is happening.

Problem link – Counting rooms

Accepted code – Accepted code
TLE and RE showing code – Rejected code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My approach- I am calling dfs function for every unvisited cell and coloring the visited cell.
The number of times dfs is called will be the answer.

>Solution :

In the Rejected code you are passing vector by value which is making copies of the the vector again and again.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading