J - Justice League

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Thirty five years ago, a group of super heroes was chosen to form the Justice League, whose purpose was to protect the planet Earth from the villains. After all those years helping mankind, its members are retiring and now it is time to choose the new members of the Justice League. In order to keep their secret identity, let’s say, secret, super heroes usually use an integer number to identify themselves. There are H super heroes on Earth, identified with the integers from 1 to H. With a brief look at the newspapers anyone can find out if two super heroes have already worked together in a mission. If this happened, we say that the two heroes have a relationship.

There must be only one Justice League in the world, which could be formed by any number of super heroes (even only one). Moreover, for any two heroes in the new league, they must have a relationship.

Besides, consider the set of the heroes not chosen to take part in the Justice League. For any two heroes on that set, they must not have a relationship. This prevents the formation of unofficial justice leagues.

You work for an agency in charge of creating the new Justice League. The agency doesn’t know if it is possible to create the League with the restrictions given, and asked for your programming skills. Given a set of super heroes and their relationships, determine if it is possible to select any subset to form the Justice League, according to the given restrictions.

 

Input

The input is composed of several test cases. The first line of each test case contains two integers separated by a single space, H (2 <= H <= 5×10 4) and R (1 <= R <= 10 5), indicating, respectively, the number of heroes and the number of relationships. Each of the following R lines contains two integers separated by a single space, A and B (1 <= A < B <= H), indicating that super hero A has a relationship with super hero B. Note that if A has a relationship with B, B also has a relationship with A. A relationship is never informed twice on a test case. 
The end of input is indicated by H = R = 0. 
 

Output

For each test case in the input print a single line, containing the uppercase letter “Y” if it is possible to select a subset of heroes to form the Justice League according to the given restrictions, or the uppercase letter “N” otherwise.
 

Sample Input

5 5
1 2
2 3
1 3
1 4
3 5
9 8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
4 3
1 2
2 3
3 4
0 0
 

Sample Output

Y
N
Y
 
 
 
 
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int ind[];
int vis[];
int t[];
bool cmp(int a,int b){
return ind[a]<ind[b];
}
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
if(n==&&m==)
break;
memset(ind,,sizeof(ind));
memset(t,,sizeof(t));
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++){
t[i]=i;
}
int u,v;
vector<int>q[];
for(int i=;i<=m;i++){
scanf("%d%d",&u,&v);
ind[u]++;
ind[v]++;
q[u].push_back(v);
q[v].push_back(u);
}
sort(t+,t+n+,cmp); for(int i=;i<=n;i++){
int temp=t[i];
if(vis[temp]==){
for(int j=;j<q[temp].size();j++){
vis[q[temp][j]]=;
ind[q[temp][j]]--;
}
}
}
int ans=;
int tmin=;
for(int i=;i<=n;i++){
if(vis[i]){
ans++;
tmin=min(tmin,ind[i]);
}
} if(ans==tmin+)
printf("Y\n");
else
printf("N\n"); }
return ;
}
 
 
 
 
 
 

HDU 1937 J - Justice League的更多相关文章

  1. HDU 1937 F - Finding Seats 枚举

    F - Finding Seats Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  2. hdu 1937 Finding Seats

    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  3. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  4. RxJava和RxAndroid

    现在RxJava和RxAndroid越来越火爆,自己在业余时间也学习了一下,感觉确实很好用,之前 为了完成页面刷新,数据请求,组件信息传递的时候,要使用handler,真的是逻辑思路很强,稍微不注意, ...

  5. SFC游戏列表(维基百科)

    SFC游戏列表 日文名 中文译名 英文版名 发行日期 发行商 スーパーマリオワールド 超级马里奥世界 Super Mario World 1990年11月21日 任天堂 エフゼロ F-Zero F-Z ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. [转] POJ图论入门

    最短路问题此类问题类型不多,变形较少 POJ 2449 Remmarguts' Date(中等)http://acm.pku.edu.cn/JudgeOnline/problem?id=2449题意: ...

  8. 2014 北京邀请赛ABDHJ题解

    A. A Matrix 点击打开链接 构造,结论是从第一行開始往下产生一条曲线,使得这条区间最长且从上到下递减, #include <cstdio> #include <cstrin ...

  9. News Master-DC and Marvel they are super heroes mother

    News Master Good evening everyone,I’m Jason,I’m glad to be news master to share something, Tonight I ...

随机推荐

  1. Linux驱动学习(编写一个最简单的模块)

    在Linux中想做驱动开发,那么一定要先熟悉module的使用和编写 一.什么是module 从名字上看就是模块的意思,我个人的理解就是一个一个的小程序,可以进行动态的安装和卸载,而在这里面就实现一些 ...

  2. 【杂题总汇】UVa-1627 Team them up!

    [UVa-1627] Team them up! 借鉴了一下hahalidaxin的博客……了解了思路,但是莫名Wa了:最后再找了一篇dwtfukgv的博客才做出来

  3. elasticsearch-dsl聚合-1

    接续上篇,本篇介绍elasticsearch聚合查询,使用python库elasticsearch-dsl进行聚合查询操作. 7.3.聚合查询 高阶概念 Buckets(桶/集合):满足特定条件的文档 ...

  4. JIRA 6.3的那些事(1):linux环境安装

    一直以来,自认为对JIRA是还算比较熟悉 从3.x 就开始使用,然后用4.x 近期公司对BUG系统进行选型: 我极力推荐JIRA  ! 然后,JIRA 的安装.部署.配置任务就给到我了: 本以为应该是 ...

  5. TCPIP协议编程:基于UDP协议的局域网聊天工具的研发

    任务目标 聊天器采用客户端/服务器(C/S)模式: 客户端利用UDP与服务器相连,客户端与客户端之间通过UDP相互通信: 服务器端具有服务器端口设置维护客户端个人信息,记录客户端状态,分配账号等: 客 ...

  6. git--分布式版本管理系统

    参考博客:廖雪峰的官方网站 一.window安装git Git官网直接下载安装程序,默认选项安装即可. 1.设置自己的git(cmd命令或者git bash进入) git config --globa ...

  7. [BZOJ3172 ][Tjoi2013]单词(AC自动机)

    Description 不稳定的传送门 某人读论文,一篇论文是由许多单词组成.但他发现一个单词会在论文中出现很多次,现在想知道每个单词分别在论文中出现多少次.单词个数<=200,单词总长度< ...

  8. jsUnpacker

    EVAL function executeEval(){ let evalCodeElt = document.getElementById("eval_code"); let e ...

  9. easyui-datagrid单选模式下隐藏表头的全选框

    easyui-datagrid可以不使用复选框来进行单选,直接使用onSelect和 singleSelect:true就可以实现单选,但是有一些用户会比较习惯使用勾选框,这时会加一列checkbox ...

  10. Python语法之com[1][:-7]

    strCom = com[0] + ": " + com[1][:-7] 如上应该是一个字符串合成,最后的[1][:-7],我理解是去除com[1]的最后7个字符. 比如com[0 ...