FZU 2141 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
Sample Output
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的更多相关文章
- 二分图点染色 BestCoder 1st Anniversary($) 1004 Bipartite Graph
题目传送门 /* 二分图点染色:这题就是将点分成两个集合就可以了,点染色用dfs做, 剩下的点放到点少的集合里去 官方解答:首先二分图可以分成两类点X和Y, 完全二分图的边数就是|X|*|Y|.我们的 ...
- hdu 5313 Bipartite Graph(dfs染色 或者 并查集)
Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...
- 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 ...
- HDU 5313——Bipartite Graph——————【二分图+dp+bitset优化】
Bipartite Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- CodeForces - 600F Edge coloring of bipartite graph
Discription You are given an undirected bipartite graph without multiple edges. You should paint the ...
- HDU 5313 Bipartite Graph(二分图染色+01背包水过)
Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...
- hdu5354 Bipartite Graph
分治+并查集.假设要求[L,mid]的答案,那么很明显,如果一条边的两个端点都>mid的话或者一个端点>mid一个端点<L,说明询问[L,mid]这个区间中任何一点时候,这一条边都是 ...
- HDU 5313 Bipartite Graph (二分图着色,dp)
题意: Soda有一个n个点m条边的二分图, 他想要通过加边使得这张图变成一个边数最多的完全二分图. 于是他想要知道他最多能够新加多少条边. 注意重边是不允许的. 思路: 先将二分图着色,将每个连通分 ...
- HDU 5313 Bipartite Graph
题意:给一个二分图,问想让二分图变成完全二分图最多能加多少条边. 解法:图染色+dp+bitset优化.设最终的完全二分图两部分点集为A和B,A中点个数为x,B中点个数为y,边数则为x × y,答案即 ...
随机推荐
- DDR(一)
P-Bank:计算机早期的一个概念.目的:匹配内存芯片和CPU芯片的数据总线的宽度.方法:并联多个内存模块. L-Bank:对内部存储阵列的分割,避免寻址冲突,提高内存效率.通过ba信号选择bank, ...
- 卸载PythonToolKit的方法
先借用官网的内容介绍一下: PythonToolkit (PTK) is an interactive environment for python. It was originally design ...
- 怎么开启PHP 的错误提示?
怎么开启PHP 的错误提示? 在php.ini 修改error_reporting = E_ALL & ~E_NOTICEdisplay_errors = On重启apache服务器在运行 ...
- Android 带checkbox的listView 实现多选,全选,反选
由于listview的一些特性,刚开始写这种需求的功能的时候都会碰到一些问题,重点就是存储每个checkbox的状态值,在这里分享出了完美解决方法: 布局文件: [html] <?x ...
- mysql字符串相关
使用MySQL,我们很多时候都会出现需要截取字符串的情况,所以关于字符串的截取的方式有必要记录下去. MySQL截取字符串的函数有: left(str, length):从左边开始截取,length是 ...
- linux进程的堆栈空间_代码段(指令,只读)、数据段(静态变量,全局变量)、堆栈段(局部变量)、栈【转】
转自:http://blog.csdn.net/gongweijiao/article/details/8207333 原文参见:http://blog.163.com/xychenbaihu@yea ...
- Mysql服务器相互作用的通讯协议包括TCP/IP,Socket,共享内存,命名管道
MySQL实现了四种通信协议 TCP/IP协议,通常我们通过来连接MySQL,各种主要编程语言都是根据这个协议实现了连接模块 Unix Socket协议,这个通常我们登入MySQL服务器中使用这个协议 ...
- 利用BAT批处理安装服务程序
@echo off @echo off set filename=LXServer.exe set servicename=Service1 set Frameworkdc=%SystemRoot%\ ...
- Pascal's Triangle II
class Solution { public: vector<int> getRow(int rowIndex) { vector<int> v; ) return v; v ...
- shell基础二十篇 一些笔记
shell基础二十篇 转自 http://bbs.chinaunix.net/thread-452942-1-1.html 研讨:Bash 内建命令 read (read命令更具体的说明见博客收藏的一 ...