URAL 1106 Two Teams (DFS)】的更多相关文章

题意 小组里有N个人,每个人都有一个或多个朋友在小组里.将小组分成两个队伍,每个队伍的任意一个成员都有至少一个朋友在另一个队伍. 思路 一开始觉得和前几天做过的一道2-sat(每个队伍任意两个成员都必须互相认识)相似然后就往那边想了--看了题解才发现这题很简单-- 我们注意到同组里的人是互不影响的,所以一个人如果已经确定在哪组的话是不会对后面进入这个组的人产生影响的. 所以我们按顺序直接搜就可以了,每个人在他朋友里面找一个已经确定组的,然后放到对面组.如果他的所有朋友都没确定,把他随便放一个组就…
S - Two Teams Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1106 Description The group of people consists of N members. Every member has one or more friends in the group. You are to write pro…
链接:http://acm.timus.ru/problem.aspx?space=1&num=1106 描述:有n(n<=100)个人,每个人有一个或多个朋友(朋友关系是相互的).将其分成两组,使每一组都有朋友在另一个组. 思路:大意就是求一个子图使其是二分图.直接用dfs染色. 实际上不是二分图,因为本题每个子集里边可以有边相连,只要满足题目给的条件就行了.比二分图简单了一些. //g++ 4.7.2 #include <cstdio> #include <iostre…
http://acm.timus.ru/problem.aspx?space=1&num=1106 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ][]; ]; int main() { int n; scanf("%d",&n); int a; memset(g,false,sizeof(g)); ; i<=n; i…
Legendary Teams Contest Time limit: 1.0 secondMemory limit: 64 MB Nothing makes as old as years. A lot of cool contests are gone, a lot of programmers are not students anymore and are not allowed to take part at the contests. Though their spirit is f…
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1106 乍一眼看上去,好像二分图匹配,哎,想不出和哪一种匹配类似,到网上查了一下,DFS染色一遍就可以啦. 两种颜色的很好写.直接没有访问的是1,然后扫邻接表,为2,DFS邻接表. #include <bits/stdc++.h> using namespace std; #define maxn 105 vector<int> G[maxn]; int color[max…
1106 结点染色 当前结点染为黑 朋友染为白  依次染下去 这题是为二分图打基础吧 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<vector> using namespace std; vector<]; ],num; void dfs(int u,int c) {…
Two Teams Time limit: 1.0 secondMemory limit: 64 MB The group of people consists of N members. Every member has one or more friends in the group. You are to write program that divides this group into two teams. Every member of each team must have fri…
Z - Bus Routes Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1137 Description Several bus routes were in the city of Fishburg. None of the routes shared the same section of road, though commo…
题意描述:给定K支队伍,每队三个队员,不同队伍之间队员可能部分重复,输出这些队员同时能够组成多少完整的队伍: DFS,利用DFS深度优先搜索,如果该队所有队员都没有被访问过,那么将该队计入结果,再去选择下一队~ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <stdlib.h> #include <map>…