hinhva's blog

By hinhva, 10 years ago, In English

Hi, I'm trying to solve problem E and I from this problem set: http://codeforces.com/gym/100463/attachments/download/2554/michigan-invitational-programming-contest-en.pdf

Currently, I have no idea how to solve them. I hope you guys can give me some hints. Thanks.

  • Vote: I like it
  • +18
  • Vote: I do not like it

»
10 years ago, # |
  Vote: I like it +18 Vote: I do not like it

Let's construct a graph where there is an edge if spies can locate at that cities. Now we should count number of ways to choose one of the ends of each edge without intersections. It's easily to see that we can solve this problem for each connected components independently, and the answer will be the product of each results. So we consider one connected component. Let's N and M be number of vertexes and number of edges in this component respectively.

Let's consider 3 cases:

  1. M = N-1 It means that the graph is a tree. So the answer is N. Because M=N-1 so we will choose N-1 vertex from N. There is N possible variants to leave some vertex. Then if we leave some vertex the other matching will be unique.

  2. M = N It means that in the graph there is exactly one cycle. Then for some edge that lies in cycle if we choose one of his ends then other matchings will be unique. So there is 2 possible ways to match. There is a corner case: if cycle consists only from one vertex(i.e. there is a loop) then there is not 2 possible choice. So the answer in this case is 1.

  3. M > N It means that we must choose some M vertexes, but we have only N vertex. So in this case answer is 0.

P.S. Sorry for my poor English.

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    In the case M = N-1, I think the answer should be the_number_of_city, not N. Also, you should be really careful with the case when a spy's position is known exactly at the beginning.