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 ...
随机推荐
- WebLogic 12c 多节点Cluster静默安装
WebLogic集群架构 Weblogic角色 AdminServer: 172.16.65.130 NodeServer: 172.16.65.131.172.16.65.132 版本 weblog ...
- Linux服务器注意事项
1.在Linux新建一个tomcat目录,执行里面的文件运行的时候 会出现权限不足的提示?解决办法:这是因为新建的文件夹,对于可执行脚本,必须先授权,进入bin目录后,执行命令 chmod 764 ...
- 【P2015】二叉苹果树(树状DP)
蒟蒻弱弱的开始做树形DP了,虽然做了这道题还是有很多不懂得地方. 这道题大意就是有一棵树,只保留其中q条边,求出剩余边的最大权值. 然后开始考虑怎么做(其实是看着题解出思路....),很容易可以想出D ...
- JS,Jquery获取屏幕的宽度和高度
Javascript: 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.b ...
- Tomcat学习之Wrapper
Tomcat学习之Wrapper 分类: WEB服务器2012-08-30 22:16 1547人阅读 评论(0) 收藏 举报 tomcatservletwrapperservletslistexce ...
- hdoj1004--Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- js享元模式
享元模式(Flyweight),运用共享技术有效地支持大量细粒度的对象. 内部状态与外部状态 内部状态存储于对象内部. 内部状态可以被一些对象共享 内部状态独立于具体的场景,通常不会改变 外部状态取决 ...
- Redis 简单介绍(知识整理笔记)
前言: Redis 介绍:轻量级.Key-Value.内存数据库.支持持久化 Redis 数据结构:string(字符串),hash(哈希),list(列表),set(集合)及 zset (sorte ...
- hdoj-1276-士兵队列训练问题(队列模拟)
题意: 新兵蛋子按照两种报数规则报数: 1.1212报数,2出队 2.123123报数,3出队 没报完一轮,检查人数,不大于3,over 略坑,必须每报完一轮检查人数,最初,按照12两种顺序报完检查人 ...
- vs2012 sln和.vcxproj有什么区别
sln是解决方案的配置,主要是管理这个方案里的多个vcxprojvcxproj是工程的配置文件,管理工程中细节比如包含的文件,引用库等一般没有sln,也可以直接打开vcxproj,也可以重新生成sln ...