POJ2492 A Bug's Life 判断二分图】的更多相关文章

给一个无向图,判断是否为二分图 是否有奇环.用染色法解决,也可以用并查集解决,时间复杂度是相同的,但是并查集用的内存少. 这里给出Bfs染色的代码 #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<vector> #include<queue> using namespace st…
Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 423    Accepted Submission(s): 161 Problem Description   This year is the 60th anniversary of NJUST, and to make the celebration mor…
785. 判断二分图 给定一个无向图graph,当这个图为二分图时返回true. 如果我们能将一个图的节点集合分割成两个独立的子集A和B,并使图中的每一条边的两个节点一个来自A集合,一个来自B集合,我们就将这个图称为二分图. graph将会以邻接表方式给出,graph[i]表示图中与节点i相连的所有节点.每个节点都是一个在0到graph.length-1之间的整数.这图中没有自环和平行边: graph[i] 中不存在i,并且graph[i]中没有重复的值. 示例 1: 输入: [[1,3], […
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Problem Description There are a group of students. Some of them may know each other, while others don't. For example, A and B know each other, B and C know each other. But this may not imply t…
The Accomodation of Students Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description There are a group of students. Some of them may know each other, while others don't. For example, A and B know each other, B and C k…
#include <iostream> #include <cstdio> #include <string.h> #include <vector> #define inf 0xfffffff using namespace std; const int maxn = 1e5 + 1e2; const int maxp = 1e3 + 1e2; //邻接表vector实现 vector<int> G[maxp]; int color[maxp]…
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8418    Accepted Submission(s): 3709 Problem Description There are a group of students. Some of them may know each ot…
题目链接 http://poj.org/problem?id=2492 题意 虫子有两种性别,有n只虫子,编号1~n,输入m组数据,每组数据包含a.b两只虫子,表示a.b为不同性别的虫子,根据输入的m组数据是否出现前后矛盾(如a.b在前面判断为同性,而后又得出a.b为异性)进行相应的输出. 思路 使用并查集求解,但该题比普通并查集题目复杂了一些,该题需要使用树中结点的权值来记录信息,在代码中使用数组r[]来记录某结点和其父结点之间的性别是否相同,若r[x]=0,则说明虫子x和其父结点同性,若r[…
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description There are a group of students. Some of them may know each other, while others don't. For example, A and B know each o…
题目链接:https://cn.vjudge.net/contest/209473#problem/C 先谈一下二分图相关: 一个图是二分图的充分必要条件: 该图对应无向图的所有回路必定是偶环(构成该环形的边的数量为偶数).暂时不证明,后证. 那么怎么判断一个图的回路是奇环还是偶环呢? 交叉染色法. 随机选择一个点,染成红色,把所有跟它相邻的点染成绿色,再由被染色的绿点出发,把相邻的点染成红色…… 即对于一个点和他相邻的点(两个点之间有边相连叫做相邻),颜色必定不同,如果相同,那么是奇环. 例如…