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. mysql完全卸载大全

    如何在Linux下卸载MySQL数据库呢? 下面总结.整理了一下Linux平台下卸载MySQL的方法. MySQL的安装主要有三种方式:二进制包安装(Using Generic Binaries).R ...

  2. Eclipse Git 插件 基本操作一【learn】

    安装GIT插件: 我的Eclipse版本为: Oxygen.2 Release (4.7.2),所以自带GIT插件,跳过安装. GIT插件配置: ①.添加好用户名和邮箱 注意下输入格式:user.na ...

  3. C#封装cef图片title不显示

    遇到Web项目在浏览器调试时tip能正常显示,在cef环境下居然没有提示.根据网上的的资料添加app.manifest文件. 并且放开这一段代码.重新编译后能够显示出tip.

  4. java基础必备单词讲解 day six

    development development development development 开发 development developmentenvironment environment en ...

  5. 灵光一现的trick

    感觉平时会丢掉好多挺好的trick…… 图论 1.图G,固定S,T.可以将任意一条边加上权值$k(k>0)$,求最大化加权后最短路. 2.图G,固定S,T.可以将任意一条边乘以权值$k(k> ...

  6. ARM S3C2440 时钟初始化流程

    1.设置lock time 2.设置分频系数 3.设置CPU到异步工作模式 4.设置 FCLK 了解 芯片的时钟原理图,以及寄存器的作用 了解芯片的晶振频率,锁相环,分频系数,以及有哪些时钟

  7. dts--tests(一)

    cmdline.py """ DPDK Test suite. Test cmdline. """ import utils from te ...

  8. php精华之独孤九剑

    首先分享一个地址 https://segmentfault.com/a/1190000013696265(这个是主要的分享,人家作者写的非常棒

  9. java多线程批量读取文件( 八)--读写分离

    package com.net.thread.future; import java.io.BufferedReader; import java.io.BufferedWriter; import ...

  10. python学习之路1(基本语法元素)

    1.变量与简单数据类型 1.1变量 变量就是给你所写代码的信息起一个名字,用来存储此信息,使信息变得更加的简洁易读, 例如:message = "Hello World!",其中m ...