Brute force in this ZIO problem

Hello guys ,

I have solved ZIO 2005 , P2 by brute force and it took me a lot of time . Any of you have a better solution for this problem ?

Thanks a lot !!

It is brute force. Another thing you can apply in this though is that if a bus stop is connected only from a single number
Like suppose

1— 4 — 8 — 9
4 — 7 — 2 — 3
.
.
.

Then 9 can never be the manager’s office. Coz, the routes from 8 to any other number(except 9) will be shorter than 9. I eliminated them like that, and I could do it in 20-30 minutes.(All the 3 sub-parts)

2 Likes

hello @sudheerays123,
Yes, there exists a better way in which we can easily solve the problem…
See the attached photo…
First, create a graph of given data like in the image below…
Then just compare the longest distance traveled to reach the Farthest point by some of the middle terms …,like, i just compared 2,1,6 and 8 and 6 comes out to be the answer.!
Hope you understood…
74614852_418258049087507_4146499321778405376_n|375x500

2 Likes

Yes i understood now
Will try for other test cases

Thanks a lot ! @sumit_king

Yes, you can also make a graph as @sumit_king told you to do, but that will lead to the same thing which I explained you. It just clears our doubts further and there is a less chance of making a silly mistake, but it will take 10 minutes or so extra

1 Like

No problem @sudheerays123

1 Like

I will try both the methods

Thanks a lot @aryan12 !!

1 Like

Happy to be of help @sudheerays123. :slight_smile:

2 Likes

@aryan12 I have added problems which i couldnt solve in discussion
Can you pls help me if you have solved any of those problems

Here is the link : ZIO problems

Thanks a lot !