Sub-Bipartite Graph

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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

3 1 0 2 1 1 2 3 3 1 2 2 3 1 3

Sample Output

1 1 0 1 1 1 2 2 1 2 1 3

Hint

This problem is special judge.

 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int g[][],color[],B,W; int cal(int p)
{
int b=,w=;
int i;
color[p]=;
for(i=;i<p;++i)
if(g[i][p] && color[i]!=color[p]) b++;
color[p]=;
for(i=;i<p;++i)
if(g[i][p] && color[i]!=color[p]) w++;
if(b>w) color[p]=,B++;
else color[p]=,W++;
} int main()
{
int T,n,m;
scanf("%d",&T);
while(T--)
{
int i,j;
scanf("%d%d",&n,&m);
memset(color,,sizeof(color));
memset(g,,sizeof(g));
int u,v;
for(i=;i<=m;++i)
{
scanf("%d%d",&u,&v);
g[u][v]=;
g[v][u]=;
} B=W=;
for(i=;i<=n;++i)
cal(i);
printf("%d",B);
for(i=;i<=n;++i)
if(color[i]==) printf(" %d",i);
printf("\n");
printf("%d",W);
for(i=;i<=n;++i)
if(color[i]==) printf(" %d",i);
printf("\n");
}
return ;
}

FZU 2141 Sub-Bipartite Graph的更多相关文章

  1. 二分图点染色 BestCoder 1st Anniversary($) 1004 Bipartite Graph

    题目传送门 /* 二分图点染色:这题就是将点分成两个集合就可以了,点染色用dfs做, 剩下的点放到点少的集合里去 官方解答:首先二分图可以分成两类点X和Y, 完全二分图的边数就是|X|*|Y|.我们的 ...

  2. hdu 5313 Bipartite Graph(dfs染色 或者 并查集)

    Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...

  3. Learning Query and Document Similarities from Click-through Bipartite Graph with Metadata

    读了一篇paper,MSRA的Wei Wu的一篇<Learning Query and Document Similarities from Click-through Bipartite Gr ...

  4. HDU 5313——Bipartite Graph——————【二分图+dp+bitset优化】

    Bipartite Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. CodeForces - 600F Edge coloring of bipartite graph

    Discription You are given an undirected bipartite graph without multiple edges. You should paint the ...

  6. HDU 5313 Bipartite Graph(二分图染色+01背包水过)

    Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...

  7. hdu5354 Bipartite Graph

    分治+并查集.假设要求[L,mid]的答案,那么很明显,如果一条边的两个端点都>mid的话或者一个端点>mid一个端点<L,说明询问[L,mid]这个区间中任何一点时候,这一条边都是 ...

  8. HDU 5313 Bipartite Graph (二分图着色,dp)

    题意: Soda有一个n个点m条边的二分图, 他想要通过加边使得这张图变成一个边数最多的完全二分图. 于是他想要知道他最多能够新加多少条边. 注意重边是不允许的. 思路: 先将二分图着色,将每个连通分 ...

  9. HDU 5313 Bipartite Graph

    题意:给一个二分图,问想让二分图变成完全二分图最多能加多少条边. 解法:图染色+dp+bitset优化.设最终的完全二分图两部分点集为A和B,A中点个数为x,B中点个数为y,边数则为x × y,答案即 ...

随机推荐

  1. Unable to find the wrapper "https"错误的解决办法

    PHP.ini默认配置下,用file_get_contents读取https的链接,就会如下错误:Warning: fopen() [function.fopen]: Unable to find t ...

  2. OpenGL拾取注意事项

    GLFrame框架本身不支持拾取,需要自己实现.以下代码是实现拾取功能的注意事项: void Test::doSelection(int xPos, int yPos) { GLfloat aspec ...

  3. 深入Java核心 探秘Java垃圾回收机制(转自http://edu.21cn.com/java/g_189_859836-1.htm)

    垃圾收集GC(Garbage Collection)是Java语言的核心技术之一,之前我们曾专门探讨过Java 7新增的垃圾回收器G1的新特性,但在JVM的内部运行机制上看,Java的垃圾回收原理与机 ...

  4. SQLServer查询速度慢的原因

    查询速度慢的原因很多,常见如下几种:  1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应.  3.没有创建计算列导致查询不优化.  4.内存 ...

  5. HorizontalScrollView的配置

    package com.exmple.jinritoutiao; import java.util.ArrayList;import java.util.Calendar;import java.ut ...

  6. java总结第三次//类和对象2、3

    四.类和对象2 主要内容:Java类的继承.方法的重写.覆盖.访问控制.super 关键字.多态性及其应用 1.继承 要求:Java只支持单继承,不允许多重继承 一个子类只能有一个父类 一个父类可以派 ...

  7. 161031、java.util.StringTokenizer使用及源码

    import java.util.StringTokenizer; public class TestStringTokenizer { public static void main(String[ ...

  8. grads 用arcgis分析站点的网格

    第一步,用工具创建渔网(要素类) 第二步:将站点excel导入,生成点要素 站点excle,点击上面节点导出数据即可. 第三步,叠加在一起,找网格编号.

  9. include指令

    include:文件加载指令(用于在JSP文件中插入一个包含文本或代码的文件.把文件插入后和原来的JSP文件合并成一个新的JSP页面.) 语法格式:<%@ include file=" ...

  10. PHP使用PHPExcel删除Excel单元格指定列的方法是怎样

    有一个系统仅公司内部和外部经销商使用,在一个导出功能中公司内部员工跟外部经销商导出的列是不一样的(某些数据是不能提供给经销商的)因为导出的数据都是一样的(某些列外数据外部没有)因此并没有单独处理,而是 ...