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. P3391 【模板】文艺平衡树(Splay)

    Splay #include<cstdio> #include<algorithm> #include<iostream> using namespace std; ...

  2. js日期转换Fri Oct 31 18:00:00 UTC+0800 2008转换为yyyy-mm-dd

    Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d ...

  3. django中的forms组件(权限信息校验,增删改查)

    1.用处 1.用户请求数据验证 2.自动生成错误信息 3.打包用户提交的正确信息 4.如果其中有一个错误了,其他的正确,则保留上次输入的内容 5.自动创建input标签并可以设置样式 6.基于form ...

  4. lambda函数,内置map()函数及filter()函数

    8.1 lambda函数 作用及意义:  1.没必要专门定义函数,给函数起名,起到精简的效果  2.简化代码的可读性 def ds(x): return 2 * x + 1 ds(5) ---11 g ...

  5. jsonp 请求和回传实现

    JSONP最主要的是可以解决跨域问题,不然谁会没事用这种格式. 下面是我用JSONP的一些心得体会: JSONP是JSON with Padding的略称.它是一个非官方的协议,它允许在服务器端集成S ...

  6. 由fastRPC产生的DB服务

    根据整理的RPC模型,在此上,根据最近的项目,发布了DB服务,操作数据库.以RPC模型,发布数据库的操作服务,主要发送SQL语句,在服务端执行:同时引入了流行的数据库连接池:服务端还发布了文件接收服务 ...

  7. 【图论 思维】cf715B. Complete The Graph加强

    zzq讲的杂题 题目大意 有一张$n​$个点$m​$条边的简单正权无向图,$S​$到$T​$的最短路为$L​$,现在有一些边的边权未知,请输出任意一种满足题意的方案. $n,m\le 500000​$ ...

  8. 01U盘PE系统制作方法

    1. 需要的工具和安装包:WinPE镜像文件 WinPE_x86.iso .已制作好的另一个启动盘(下文以映像总裁为例,当然也可以使用大白菜.U启动等) . 电脑.准备制作PE系统的空U盘 2. 还原 ...

  9. Vue项目部署遇到的问题及解决方案

    写在前面 Vue-Router 有两种模式,默认是 hash 模式,另外一种是 history 模式. hash:也就是地址栏里的 # 符号.比如 http://www.example/#/hello ...

  10. php学习【2】

    1:运算符 <?php $x=1; echo 1+1;//算术运算符 echo $x+=5;//赋值运算符 echo "<br/>"; echo $x++; ec ...