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

Автор Firestone, история, 5 лет назад, По-английски

Given a graph with n vertices (2 <= n <= 200). Find the largest set of vertices that each two vertices are connected.

Time: 1s, memory: 256MB

Input: First line contains two numbers n and k — the vertices and the edges.

Next k lines contains the k edges.

Output: The first line contain one number — The size of the set

The second line represents the vertices in the set. If there are more than one set that have the maximum size, print the set that is lexicographically smallest.

Example:

Input:

5 3

1 3

1 4

2 5

Output:

2

1 4

How can I solve this problem? Can you help me with this? Thank you!

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

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

How is your problem different from https://en.wikipedia.org/wiki/Clique_problem?

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

Perform depth first search to find all the connected( By u,v are connected I assume there is a path from u to v) components and the number of vertices in each connected component.

This gives the answer i think.

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

Well first, I doubt the memory limit is 256GB (it's probably 256MB). Second, as Hodobox stated, this is the Clique problem which is NP-Hard, so you should probably clarify what the problem means.