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

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

http://mirror.codeforces.com/problemset/problem/543/D

I did not understand the editorial so I wrote a solution of my own. But I don't understand the tricky cases where it fails. Here is my submission ID 11679268 . My logic is simple:

  1. Do DFS with "1" as root , store results in dp[i]

  2. result[1]=dp[1]

  3. result[i]=(1 + result[parent_of_i]/(dp[i]+1)) * dp[i] % mod;

Where is the logic wrong? I couldn't figure it out.

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

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

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

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

To divide result[parent_of_i]/(dp[i]+1) it's better to precalc prefix and suffix multiplications ans just calc something like pref[i-1]*suff[i+1]

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

Still couldn't fix the bug when (result[parent_of_i]=0 and dp[i]=1000000006) . vintage_Vlad_Makeev can you please explain how prefix and suffix are calculated ?