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

Автор Ahmed_Morsy, 12 лет назад, По-английски

in this problem (http://codeforces.me/contest/165/problem/D) there is a condition which makes it easy which is "there exists no more than one vertex, whose degree is more than two" so what if this condition didnot exist ?

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

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

I think this is a more simple variation of HLD. The quote:

there exists no more than one vertex, whose degree is more than two

means that the graph can be easily separated in chains. Find the vertex with degree greater than 2(if such a vertex exists). Then this is the beginning of all chains. If such vertex doesn't exist, find an unused vertex with degree 1 and make it the beginning of a new chain. Repeat this until all vertexes become used. Then for each chain build some data structure that can handle this queries(for example you can use a fenwick tree).

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

Another option is to read the editorial where is described a similar idea to the one that I described some minutes ago.

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

You may find this helpful: http://codeforces.me/blog/entry/10025