patelkishan651's blog

By patelkishan651, history, 4 weeks ago, In English,

Problem link- https://codeforces.com/contest/1167/problem/C

What can I do to reduce the time? I used dfs. My solution- https://codeforces.com/contest/1167/submission/54633342

Thanks!

 
 
 
 
  • Vote: I like it
  • -14
  • Vote: I do not like it

»
3 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

You don't have to run dfs from every friend. Once solve the problem for one friend i, then you will know the answer for every friend j in i's connected component. So you only need to run dfs on friends who aren't in connected components that have already been solved.