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

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

Hello Codeforces!

Today was Codeforces Round #720 (Div.2), in which I solved problem D — Nastia Plays with a Tree. As I find my solution different from the solutions I heard of after the contest, I will explain it in detail in this blog post. I will note that you still might find value in reading this if you solved the problem, as my proposed solution also maintains at every stage the graph being a forest (i.e I don't create any cycles).

The Solution

Solution By FiveSixFiveFour

This was very challenging to implement during the contest yet eventually I got AC 10 minutes before the end of the round. Thanks for the contest! :D

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

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Auto comment: topic has been updated by lior5654 (previous revision, new revision, compare).

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

Auto comment: topic has been updated by lior5654 (previous revision, new revision, compare).

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I will note here that my first idea was to simply guess that we should only keep a diameter and remove all other edges. I heard others in the community tries the same approach & failed. Here is a counterexample to that approach:

The answer is 1, but the diameter idea will give an answer of 7.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Thank you for this editorial!

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Also posted here: https://cp-notes.com/notes/fivesixfivefour/CodeForces/1521/D

To learn more about cp-notes, read this blogpost: https://codeforces.me/blog/entry/90384

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Ok i got it from your code. It seems that after calculating the sdp[] , cdp[] and where from a given node we can go next (i.e should we connect it to two, one or no node), the structure of set of simple paths become unique? and by using dfs2() we are just tracing back those paths?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Do we need to cut the 5-13 edge in the example?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Calculating cdp[] ,sdp[],cn[] and sn[] is fine but after calculating all these stuffs how do we find the chains? It's bit unclear.