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,答案即 ...
随机推荐
- 夺命雷公狗—angularjs—8—ng-class的简单用法
我们在正常的业务处理中往往会遇到一些逻辑类的问题,比如各行换色,现在angularjs里面也给我们提供了一个小小的的class处理的方式,废话不多说,如下所示: <!doctype html&g ...
- Android 屏幕滑动事件
http://blog.csdn.net/iamfafa/article/details/6316062 Android里有两个类 android.view.GestureDetector andro ...
- Another app is currently holding the yum lock; waiting for it to exit...另一个应用程序在占用yum lock,等待其退出。
这种情况下通常是由于yum的时候意外退出造成的,虽然也给出提示当前占用进行的id,但是执行kill -9 3599 强制杀死进程后,情况依然没能改变. 备注:(-9是强制杀死) 主要原因是因为,yum ...
- [CrunchBang]中文字体美化
安装必要的字体包 sudo apt-get install ttf-droid ttf-wqy-zenhei xfonts-wqy ttf-wqy-microhei ttf-arphic-ukai t ...
- linux计划任务运行php文件的方法
在linux下,借助crontab,设置计划任务每天6点10分执行filename.php文件,写入一行时间到log日志中. 创建计划任务的脚本: dos2unix /path/to/filename ...
- 图像处理工具包ImagXpress教程:Accusoft不同组件间的图像数据传递
图像处理工具包ImagXpress的开发厂商Accusoft Pegasus旗下有多种图像处理相关的控件,但是这些图像处理控件之间的如何加传递图像数据呢?在ImagXpress 11版本之前,是需要将 ...
- Tomcat端口被占用快速解决方案
在dos下,输入 netstat -ano|findstr 8080 //说明:查看占用8080端口的进程 显示占用端口的进程 taskkill /pid 6856 /f //说明,运行 ...
- 【JQGRID DOCUMENTATION】.学习笔记.6.Editing:Common Rules
1 公共编辑属性 要在grid中显示数据的一个关键原因是能简单快速地编辑它.jgGrid提供三种编辑方式: cell editing:编辑指定cell inline editing:编辑同一行的几个c ...
- struts2的两个核心配置文件
struts2的两个核心配置文件,即:struts.default.xml和struts.properties A,位置:都在struts2-core-version.jar文件中 B,作用,stru ...
- 打开开源项目总得.md文件
google了一些: 78 Tools for Writing and Previewing Markdown http://mashable.com/2013/06/24/markdown-too ...