Wrestling Match 2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)hdu 5971
来源:互联网 发布:c500软件下载 编辑:程序博客网 时间:2024/05/02 01:27
Wrestling Match
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1034 Accepted Submission(s): 391
Problem Description
Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is "good player”, the rest is "bad player”. Now, Xiao Ming is referee of the wrestling match and he has a list of the matches in his hand. At the same time, he knows some people are good players,some are bad players. He believes that every game is a battle between the good and the bad player. Now he wants to know whether all the people can be divided into "good player" and "bad player".
Input
Input contains multiple sets of data.For each set of data,there are four numbers in the first line:N (1 ≤ N≤ 1000)、M(1 ≤M ≤ 10000)、X,Y(X+Y≤N ),in order to show the number of players(numbered 1toN ),the number of matches,the number of known "good players" and the number of known "bad players".In the next M lines,Each line has two numbersa, b(a≠b) ,said there is a game between a and b .The next line has X different numbers.Each number is known as a "good player" number.The last line contains Y different numbers.Each number represents a known "bad player" number.Data guarantees there will not be a player number is a good player and also a bad player.
Output
If all the people can be divided into "good players" and "bad players”, output "YES", otherwise output "NO".
Sample Input
5 4 0 01 31 43 54 55 4 1 01 31 43 54 52
Sample Output
NOYES题意: 给的数据是否能分成 good player 或者 bad player 两个队伍, 利用dfs染色来区分是否是二分图。建图,首先把已知的 good or bad players 开始dfs,再对未知的进行dfs 染色 + 判断。 如果还有剩余没有搜索到的点则 false#include <stdio.h>#include <iostream>#include <algorithm>#include <cmath>#include <vector>#include <string.h>using namespace std;vector<int> map[1005];int v;int color[1005];bool dfs(int p, int c) { color[p] = c; for (int i = 0 ; i < map[p].size(); ++i) { if (color[map[p][i]] == c) { return false; } if (color[map[p][i]] == 0 && !dfs(map[p][i], -c)) //color == 0 判断 该点是否已被染色 已被染色就不dfs了 return false; } return true;}void solve() { for (int i = 1; i <= v; ++i) { if (color[i] == 1) { if (!dfs(i, 1)) { cout << "NO" << endl; return; } } } for (int i = 1; i <= v; ++i) { if (color[i] == -1) { if (!dfs(i, -1)) { cout << "NO" << endl; return; } } } for (int i = 1; i <= v; ++i) { if (color[i] == 0) { if (!dfs(i, 1)) { cout << "NO" << endl; return; } } } for (int i = 1; i <= v; ++i) { if (color[i] == -5) { cout << "NO" << endl; return; } } cout << "YES" << endl;}int main() { int n, a, b; int x, y; while (cin >> v >> n >> a >> b) { for (int i = 1; i <= v; ++i) { map[i].clear(); color[i] = -5; } for (int i = 0; i < n; ++i) { cin >> x >> y; color[x] = 0; color[y] = 0; map[x].push_back(y); map[y].push_back(x); } for (int i = 0; i < a; ++i) { cin >> x; color[x] = 1; } for (int i = 0; i < b; ++i) { cin >> x; color[x] = -1; } solve(); }}
0 0
- Wrestling Match 2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)hdu 5971
- 【HDU 5971 Wrestling Match】+ 2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学) + 二分图染色
- 【HDU 5980 Find Small A】+ 2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)
- HDU 5974 A Simple Math Problem(数学解方程)——2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)
- HDU-5971 Wrestling Match (2016ACM/ICPC亚洲区大连站)
- hdu5971 Wrestling Match(染色法判二分) 2016ACM/ICPC亚洲区大连站
- hdu 5971 Wrestling Match 判断能否构成二分图 [Problem A]2016ACM/ICPC亚洲区大连站
- 2016ACMICPC亚洲区大连站重现赛1001 Wrestling Match
- HDU 5974 A Simple Math Problem(2016ACM/ICPC亚洲区大连站-重现赛 D题)
- HDU 5971 icpc 大连 A Wrestling Match
- HDU 5971 && 2016ICPC大连 A: Wrestling Match(二分图判断)
- HDU 5971 Wrestling Match(dfs)2016 icpc 大连 A题
- HDU 5950 Recursive sequence(2016ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
- HDU 5971 Wrestling Match 2016大连区域赛
- 2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学) HDU 5512 Pagodas
- HDU 5512 Pagodas 2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)
- HDU5971, 2016ACM/ICPC亚洲区大连站第一题
- 2016ACM/ICPC亚洲区大连站【solved:10 / 11】
- Romote_login_passwordfile
- 日志无法归档问题解决
- 转载 对一个全新的环境,首先应该了…
- 获取当前的SCN
- 查看flashback的开关状态
- Wrestling Match 2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)hdu 5971
- 使用oracle 的闪回功能
- Linux命令--kill
- 2009年06月05日
- Recyclebin的应用(转载)
- 关于闪回恢复区(转)
- dual表
- windows 启停Oracle服务
- Get和Post请求区别