HappyCoder's blog

By HappyCoder, 10 years ago, In English

Hello, Can anyone help me with this problem? After some days of thinking i notice that if we have popular cow A answer will be just all cows which A thinks is popular.But i have no idea how to find cow which is popular by every other.Can anyone help me?

Thank you.

P.S.any help on russian language are welcome...

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

»
10 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Reverse graph and find all strongly connected components. Let's component C is first component in topological sort order. If you can reach all other components from C — all cows in C are "popular", otherwise there is no popular cows.