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

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

Hello I have been trying to come up with an idea for the following graph theory problem :

Given an undirected graph of N vertices and E edges , You have to process a list of Q queries. In query q (1 <= q <= Q) , you remove some edge e , and you are to report the number of components in the new graph. Removal of each edge is permanent , i.e for query #q you should assume that ALL the given q edges have been removed.

N , E and Q can be at most 200,000 Thanks a lot!

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

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

You can start from end and add edges to the graph.

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

It's exactly this problem: http://acm.timus.ru/problem.aspx?space=1&num=1671

Solution is in Rev. 1.

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

Thanks a lot ! I learnt the concept of disjoint sets and got accepted. Is anyone aware of some problems in which you need to use both "union by rank" and "path compression" to get AC ?