Блог пользователя pas.andrei

Автор pas.andrei, история, 9 лет назад, По-английски

I am trying to solve this problem in which I am given a number n, representing the number of vertexes in a undirected graph. On the next line there are n natural numbers representing the degree of the respective vertex. I am asked to find the edges, such that the graph is connected.

n<=5000 and it is forbbiden that two or more edges connect the same two vertexes.

LE: Also, there will always exist a graph with the degrees given in the tests.

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

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

First condition : The sum of degrees of a graph must be even. So first you can sum all of your degrees must be even. ( however this is not a sufficient condition).

Second condition : Every node in your graph must have at least degree 1, and at most degree N-1. (Also not a sufficient, but rather necessary condition).

The sequence 3,3,3,1 meets the above two conditions, however no graph corresponds to it.

If both of these conditions are not met, then you should output there is no such graph, however if they do, it requires a complex theorm to compute that is somehow defined inductively ( google it). Do you have a link to this problem? Once you determine if it's graphical, it should be easy to implement it.

»
9 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится
  • »
    »
    9 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Yeah, I have found that theorem, but it says the conditions for which exists a graph with given degrees, but not how to construct one.

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

You can use Havel Hakimi Algorithm wich is described clearly in the link!! :)

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

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

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

Hii can anyone share the conclusion or resources from where we can read about constructing a connected graph given the degree of sequences...