codeforce 103B Cthulhu
2 seconds
256 megabytes
standard input
standard output
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with n vertices and m edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.
To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.
It is guaranteed that the graph contains no multiple edges and self-loops.

The first line contains two integers — the number of vertices n and the number of edges m of the graph (1 ≤ n ≤ 100, 0 ≤ m ≤
).
Each of the following m lines contains a pair of integers x and y, that show that an edge exists between vertices x and y(1 ≤ x, y ≤ n, x ≠ y). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.
Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.
题意:所有给定的点和边形成一个连通图,至少存在三个有根树, 且树的根形成一个环;
题解:
- 因为没有重边和自环,因此只要形成一个环就至少有三个点,而三个点就可以
- 分割成三棵有根树。因此只要满足图是联通的且存在环就满足题意。
- 可以用并查集检查是否联通,如果联通且存在环则必定有点数等于边数。
#include<bits/stdc++.h>
using namespace std;
int par[];
int find(int x)
{
if(par[x]==x)return x;
return par[x]=find(par[x]);
}
void unite(int x,int y)
{
x=find(x);y=find(y);
if(x!=y)par[x]=y;
}
int main()
{
int n,m;scanf("%d%d",&n,&m);
for(int i=;i<;i++)par[i]=i;
for(int i=;i<m;i++)
{
int x,y;scanf("%d%d",&x,&y);
unite(x,y);
}
bool bb=;
for(int i=;i<=n;i++)
if(find()!=find(i))bb=;
if(n!=m)bb=;
if(bb)printf("FHTAGN!\n");
else printf("NO\n");
return ;
}
codeforce 103B Cthulhu的更多相关文章
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- Codeforce Round #216 Div2
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- codeforce 375_2_b_c
codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...
- codeforce 367dev2_c dp
codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...
- 三维dp&codeforce 369_2_C
三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...
- 强连通分量&hdu_1269&Codeforce 369D
强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...
- 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D
[树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...
- 解题报告:codeforce 7C Line
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...
随机推荐
- JAVA基础补漏--字符串
字符串常量池 String a="abc"; String b="abc"; char[] str = {"a","b" ...
- ZooKeeper服务-数据模型
ZooKeeper是一个具有高可用性的高性能协调服务. 数据模型 ZooKeeper维护着一个树形层次结构,树中的节点被称为znode.Znode可以用于存储数据,并且有一个与之相关联的ACL(Acc ...
- 在eclipse中使用Github进行单元测试
时间分配是找资料60%,动手实践40%.因为之前一直没怎么好好学习,导致看到使用Gunit进行单元测试的时候感觉像是看到了一行符号一样不知所措,还好现在搜索引擎很强大,找资料学习中间有找到一个现成的傻 ...
- JMeter接口测试报错,反馈和postman不一样(一)
今天发现一个小的细节 同样一条请求,postman里面直接写就好 JMeter里面需要把编码加上 例如,同样一句话 postman里面这么写,返回值为 但是在JMeter里面这么写 显示结果为 在这里 ...
- volume image
http://docs.openstack.org/user-guide/cli_nova_launch_instance_from_volume.html http://docs.openstack ...
- Spring Cloud实战微服务入门
1.spring cloud是什么? 是一个快速构建分布式系统的工具集,构建于Spring Boot之上 2.spring cloud 的特点 约定优于配置 开箱即用.快速启动 适用于各种环境 轻量级 ...
- jQuery download file
jQuery.download = function (url, method, p, c, e, i, o, goodsType, reciveUser, suplier) { jQuery('&l ...
- Asp.net 检测到有潜在危险的 Request.From值
因为Asp.net对客户端提交的数据进行了基本的安全验证,检测是否有最基础的 sql注入 或者 xss跨站脚本攻击代码. 如果你提交了:</div><script type=&quo ...
- OUTlook无法预览xls文件
outlook可以正常预览doc,pdf,jpg格式的附件,但是xls和xlsx格式就是不能预览.找了好多网络上的办法,都是不行,最终还是找一个靠谱的办法,记录一下 这个方法非常有用:如题, 本人安装 ...
- BW信息STMS传输
项目时先接过来的.前面的人建了很多数据源,信息对象.我也建了不少.最后分成三个包.非常混乱,信息对象不在一个包里.导入报错.先后顺序也没有逻辑.可为难我了. 本来想着是全部释放掉,然后在传输连接收集自 ...