zoukankan      html  css  js  c++  java
  • A

    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".

    InputInput 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.OutputIf all the people can be divided into "good players" and "bad players”, output "YES", otherwise output "NO".Sample Input

    5 4 0 0
    1 3
    1 4
    3 5
    4 5
    5 4 1 0
    1 3
    1 4
    3 5
    4 5
    2

    Sample Output

    NO
    YES

    Hint

    /*
    * @Author: lyuc
    * @Date:   2017-05-01 15:48:50
    * @Last Modified by:   lyuc
    * @Last Modified time: 2017-05-01 20:33:47
    */
    /**
     * 题意:有n个人每个人只能是好人或者是坏人,给你n对人的关系,每对的中两个人的关系是对立的,一定有一个
     *         是坏人一个是好人,并且给了 x个确定是好人的编号, y个确定是坏人的编号,现在让你判断,是否能将
     *         所有人划分成两个阵营(有人的身份不能确定也不行)
     *
     * 思路:裸的二分染色,按照输入情况进行建边,然后按照输入的x,y进行染色判断如果有矛盾那一定是不行的,
     *         最后在讲给出的条件进行染色,最后如果有身份不明的人就可以除去了
     */
    #include <stdio.h>
    #include <vector>
    #include <string.h>
    #include <queue>
    #include <iostream>
    using namespace std;
    int n,m;
    int x,y;
    int a[10005],b[10005];
    vector<int>edge[1005];
    int vis[1005];
    bool ok;
    int str;
    void bfs(int u,int flag){
        queue<int>q;
        q.push(u);
        vis[u]=flag;
        while(!q.empty()){
            int tmp=q.front();
            q.pop();
            for(int i=0;i<edge[tmp].size();i++){
                int v=edge[tmp][i];
                if(vis[v]==vis[tmp]){
                    ok=false;
                    return;
                }
                if(vis[v]==0){
                    vis[v]=(-vis[tmp]);
                    q.push(v);
                }
            }
        }
    }
    void init(){
        ok=true;
        memset(vis,0,sizeof vis);
        for(int i=0;i<1005;i++){
            edge[i].clear();
        }
    }
    int main(){
        // freopen("in.txt","r",stdin);
        while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF){
            init();
            for(int i=0;i<m;i++){
                scanf("%d%d",&a[i],&b[i]);
                edge[a[i]].push_back(b[i]);
                edge[b[i]].push_back(a[i]);
            }
            for(int i=0;i<x;i++){
                scanf("%d",&str);
                if(vis[str]==-1){
                    ok=false;
                }
                bfs(str,1);
            }
            for(int i=0;i<y;i++){
                scanf("%d",&str);
                if(vis[str]==1){
                    ok=false;
                }
                bfs(str,-1);
            }
            for(int i=0;i<m;i++){
                if(vis[a[i]]==0&&vis[b[i]]==0)
                    bfs(a[i],1);
            }
            for(int i=1;i<=n;i++){
                if(vis[i]==0){
                    ok=false;
                    break;
                }
            }
            printf(ok?"YES
    ":"NO
    ");
        }
        return 0;
    }
  • 相关阅读:
    netstat命令
    为什么 netstat 对某些服务只显示了 tcp6 监听端口
    端口状态说明 LISTENING、ESTABLISHED、TIME_WAIT及CLOSE_WAIT
    进程启动时主线程创建过程分析
    [Kali]关机卡死,google拼音无法输入
    [白帽子讲WEB安全]XSS <Cross Site Script>
    [白帽子将WEB安全笔记]浏览器安全
    [白帽子将WEB安全笔记]我的安全世界观
    mongodb高可用集群 3 ---分片与副本集结合
    python计算年龄小程序
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6793044.html
Copyright © 2011-2022 走看看