Vasillia's blog

By Vasillia, history, 19 months ago, In English

This is my solution for a problem F Is it flower? from a Div 3 codeforces round 863. https://mirror.codeforces.com/contest/1811/submission/205309461

I dont realy understand why do i get TLE. I think my bfs algorithm passes through every node of the graph only once which i think should not get TLE. Can someone tell me why is this program too slow?

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
19 months ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

Your problem is in passing the graph vector in function of BFS as a parameter by value, not by reference. Because of this, it is copied to temporary memory on each call. So, one added character removes TL — https://mirror.codeforces.com/contest/1811/submission/205349622.

You can read more about this here — https://cplusplus.com/doc/tutorial/functions/.