Блог пользователя Doritos4

Автор Doritos4, история, 6 лет назад, По-английски

I'm getting wa31 for this problem ( my submission ).

First, I find all vertices that can be reached from the capital. Then, I look at all vertices which have indegree equal to 0. These vertices must have an edge directly connecting them to the capital and can obviously be visited in any order. Now, if unvisited vertices remain, they must form a cycle. I visit these vertices next ( again, in any order).

Please help

Edit : I'm getting wa32 now:(

  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

Part two of your algorithm is not correct. You can't visit vertices in any order. For example a test case

5 4 1
3 2
3 4
4 5
5 3

If you visit vertices in order 2 3 4 5 you will get two additional edges (1->2 and 1->3). But if you visit vertices in order 3 4 5 2 you will get only one addition edge (1->3), and the answer for the test case is 1.