染色判断二分图+补图

比赛的时候题意居然是反的,看了半天样例都看不懂 。。。。

Divide Groups

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 456    Accepted Submission(s): 172

Problem Description

  This year is the 60th anniversary of NJUST, and to make the celebration more colorful, Tom200 is going to invite distinguished alumnus back to visit and take photos.
  After carefully planning, Tom200 announced his activity plan, one that contains two characters:
  1. Whether the effect of the event are good or bad has nothing to do with the number of people join in.
  2. The more people joining in one activity know each other, the more interesting the activity will be. Therefore, the best state is that, everyone knows each other.
  The event appeals to a great number of alumnus, and Tom200 finds that they may not know each other or may just unilaterally recognize others. To improve the activities effects, Tom200 has to divide all those who signed up into groups to take part in the activity at different time. As we know, one's energy is limited, and Tom200 can hold activity twice. Tom200 already knows the relationship of each two person, but he cannot divide them because the number is too large.
  Now Tom200 turns to you for help. Given the information, can you tell if it is possible to complete the dividing mission to make the two activity in best state.
 

Input
  The input contains several test cases, terminated by EOF.
  Each case starts with a positive integer n (2<=n<=100), which means the number of people joining in the event.
  N lines follow. The i-th line contains some integers which are the id
of students that the i-th student knows, terminated by 0. And the id starts from 1.
 

Output
  If divided successfully, please output "YES" in a line, else output "NO".
 

Sample Input
3
3 0
1 0
1 2 0
 

Sample Output
YES
 

Source
 

Recommend
liuyiding
 
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;

int guanxi[111][111],color[111];
typedef struct
{
    int to,next;
}Edge;

Edge E[21000];
int Adj[21000],Size=0;

void Init()
{
    Size=0;
    memset(Adj,-1,sizeof(Adj));
}

void Add_Edge(int u,int v)
{
    E[Size].to=v;
    E[Size].next=Adj;
    Adj=Size++;
}

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        memset(guanxi,0,sizeof(guanxi));
        for(int i=1;i<=n;i++)
        {
            int x;
            while(scanf("%d",&x)&&x)
            {
                guanxi[x]=1;
            }
        }
        Init();
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(i==j) continue;
                if(!guanxi[j]||!guanxi[j])
                {
                    Add_Edge(i,j);
         //           printf("%d---->%d\n",i,j);
                }
            }
        }
        memset(color,0,sizeof(color));
        bool flag=true;
while(true)
{
        if(flag==false) break;
        int pos=-1;
        for(int i=1;i<=n;i++)
        {
            if(Adj==-1) continue;
            else if(color!=0) continue;
            else
            {
                pos=i;
                break;
            }
        }
       // printf("pos:   %d\n",pos);
        if(pos==-1) break;
        queue<int> q;
        q.push(pos);color[pos]=1;
        while(!q.empty())
        {
            if(flag==false) break;
            int u=q.front(); q.pop();
            for(int i=Adj;~i;i=E.next)
            {
                int v=E.to;
               // printf("%d------>%d\n  %d   %d\n",u,v,color,color[v]);
                if(color[v]==0)
                {
                    color[v]=-color;
                    q.push(v);
                }
                else if(color[v]==color)
                {
                    flag=false;
                    break;
                }
         //        printf("%d------>%d\n  %d   %d\n",u,v,color,color[v]);
            }
        }
}
        if(!flag)
            puts("NO");
        else
            puts("YES");
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )
 

最新文章

  1. slf4j
  2. 谈谈GIS与地理学语言
  3. ASP.NET获取IP的6种方法 ( 转)
  4. CQRS学习——IOC,配置,仓储隔离以及QueryEntry[其三]
  5. BZOJ1334: [Baltic2008]Elect
  6. 数据搬运工DSS~介绍
  7. UIScrollView -2(UIScrollView 与 UIPageControl的使用): 分页查看图片
  8. CentOS6.5下使用NetHogs监控进程网络使用情况
  9. poll调用深入解析
  10. SLF4J warning or error messages and their meanings(转)
  11. linux下串口通信与管理
  12. OC-之AFNetworking与ASIHTTPRequest对比
  13. Exchange Server 内部版本号和发行日期汇总
  14. laravel call传参
  15. Vim里常见的几个不可见字符
  16. 网络拓扑自动发掘之三层设备惯用的SNMP OID的含义
  17. HTML(六)--总结
  18. 将excel中的数据填入word模板中-VBA
  19. 如何在CentOS7上安装Python3及对应问题
  20. discuz回贴通知插件实现-配置邮件服务器

热门文章

  1. MVC项目经验杂谈
  2. linux 设置mysql 数据库编码utf8
  3. 《JavaScript权威指南》学习笔记 第一天。
  4. wcf第2步之服务端标准配置文件
  5. SortedSet接口
  6. 【经典】C++&amp;RPG对战游戏
  7. h5移动端滑动的细节
  8. thinkphp查询
  9. 界面调试工具reveal
  10. js的元素对象