Description

Given a simple undirected graph G with n vertices and m edges, your task is to select a sub-bipartite graph of G with at least m/2 edges.

In the mathematical field of graph theory, a bipartite graph (or bigraph) is a graph whose vertices can be divided into two disjoint sets U and V such that every edge connects a vertex in U to one in V; that is, U and V are each independent sets. Equivalently, a bipartite graph is a graph that does not contain any odd-length cycles.

Equivalently, a bipartite graph is a graph that does not contain any odd-length cycles.

In the mathematical field of graph theory, a subgraph is a graph G whose graph vertices and graph edges form subsets of the graph vertices and graph edges of a given graph G..

In graph theory, a simple graph is a graph containing no self-loops or multiple edges.

from wikipedia

Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case starts of two numbers N and M, representing the number of vertices and the number of edges, then M lines follow. Each line contains two integers x and y, means that there is an edge connected x and y. The number of nodes is from 1 to N.

1 <= T <= 100, 1 <= N <= 100, 0 <= M <= 10086

Output

For each case, you should output two lines to describe your sub-graph, the first line is the set of U and the second line is the set of V.

Each line should output an integer F first, which is the total number of the vertices in this set, then F integers follow which are the number of each vertex of this part, see sample input and sample output for more details.

You can assume that the answer is always existed.

Sample Input

31 02 11 23 31 22 31 3

Sample Output

1 101 11 22 1 21 3

Hint

This problem is special judge.


第一场组队赛啊,妹的QAQ

题意:给定n个点,m个边,要求删去最多一半的边使得原有点集形成二分图

做法:贪心的思路,既然我们想要保留尽量多的边,那么每次有新点选择加入的就是跟自己连边少的集合……没了T^T

#include<cstdio>
#include<cstring>
using namespace std;
int n,m,t;
int num1[100],num2[100];
bool fl[120][120];
int main()
{
   // freopen("cin.txt","r",stdin);
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        memset(fl,0,sizeof(fl));
        while(m--)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            fl[a][b]=fl[b][a]=1;
        }
        int pos1=0,pos2=0;
        for(int i=1;i<=n;i++)
        {
            int tmp1=0,tmp2=0;
            for(int j=1;j<=pos1;j++)
            {
                if(fl[i][num1[j]])tmp1++;
            }
            for(int j=1;j<=pos2;j++)
            {
                if(fl[i][num2[j]])tmp2++;
            }
            if(tmp1<tmp2)num1[++pos1]=i;
            else num2[++pos2]=i;
        }
        printf("%d",pos1);
        for(int i=1;i<=pos1;i++)printf(" %d",num1[i]);
        puts("");
        printf("%d",pos2);
        for(int i=1;i<=pos2;i++)printf(" %d",num2[i]);
        puts("");
    }
    return 0;
}