- Time limit: 3.00 s
- Memory limit: 512 MB
Let be a simple, undirected graph; here is the set of nodes and is the set of edges.
The density of graph is , where is the number of edges and is the number of nodes.
We define an induced subgraph as follows. Let be a nonempty subset of nodes. Then the subgraph induced by , in notation , is formed by deleting all nodes that are not in . Naturally, whenever you delete a node, you will have to delete all edges connected to it as well.
Given a graph , your task is to find a set such that the density of is as large as possible. We say that is a densest subgraph of .
Let us look at a simple example. Consider a graph with the set of nodes and that contains the edges , , , , , and . Now the density of is . If you select e.g. , you will have a subgraph with only edge and nodes, so the density of is only ; this is clearly a bad choice. However, if you select , then you will have a subgraph with edges and nodes; the density of is . This is the best possible choice in this case; there is no induced subgraph with a higher density.
Input
The first line contains two numbers, and . This indicates that the input graph contains nodes and edges. The nodes are labelled .
Then there are lines that list the edges. On each line there are two numbers, and , with and . This indicates that there is an edge , that is, there is an undirected edge between the nodes and in graph . Each edge is listed only once.
Output
Output a description of a densest subgraph . First, output a line with two numbers, and , where is the number of nodes in and is the number of edges in .
Then output one line with numbers: the labels of the nodes that are contained in subset .
If there are multiple equally dense subgraphs, you can output any such solution.
Limits
Example
Input:
5 6 1 2 2 3 2 4 3 4 2 5 3 5
Output:
4 5 2 3 4 5
Picture of the example: