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

Автор babjamal, история, 32 часа назад, По-английски

Recently I have come across a problem of an IUPC contest, where the problem asks for the summation of the mex value of all subtrees of a tree for each vertex where the vertex is the root of the tree. The detailed statement is given below or can be found in I-Mexy.

Statement

Can anyone give me hints or provide any resources about this topic?

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

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

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

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

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

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

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

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

You can do this with Small-to-Large merging in O(N * log^2 N) time, search on USACO Guide for small-to-large there is a topic.

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

    OK I have been able to solve the problem using this technique for a single rooted tree. But what about to solve the problem for each root/vertex?

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

      Oh, I didn't read that part of the problem, my bad I thought it was for a single root only!

»
28 часов назад, # |
Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

probably it can be (over)solved by root rotating and mex on segment queries.

supporse we know mex for each subtree initially (root=0). if r is root and c its child we can rotate this edge to make c as root. how will mexes change? mex(c) will be mex of all numbers and mex(r) will be mex of numbers except subtree of c (current subtree)

so current subtree is defined by oriented edge. in tree with root 0 this will be subtree or... undertree (how to call it better?). if we concate euler tour of tree twice than both subtree and undertree becomes segment. and we can ask mex on segment in O(logn).

upd (I got AC). ok we need only mex of each subtree (for init) and mex for each not subtree (for rotating). this can be found somehow easy or by mex on segments query (O(qlogn)).