当前位置:网站首页>A - deep sea exploration
A - deep sea exploration
2022-06-28 08:31:00 【Angeliaaa】
A long, long time ago , A beautiful man came to the seaside , The sea was stormy . The beautiful man hopes to find a mermaid in the sea , But unfortunately he only found the octopus .
However , On the other side of the world , People are actively collecting information about monster behavior , In order to develop powerful weapons to deal with the octopus monster . Due to the frequent occurrence of earthquakes , And bad weather , So our satellites can't locate monsters well , So they can't hit the target well . The analysis results of the first shot will be reflected in a picture by n Points and m On an undirected graph composed of edges . Now let's determine whether this picture can be regarded as an octopus monster .
For the sake of simplicity , We assume that the shape of the octopus monster is like this , He has a spherical body , Then there are many tentacles attached to his body . It can be represented as an undirected graph , In the graph, it can be considered as three or more trees ( Representative tentacle ) form , The roots of these trees are in a ring in the graph ( This ring represents a spherical body ).
Title assurance , There are no duplicate edges in the graph , There is no self link .
Input
A single set of test data
The first line gives two numbers ,n Represents the number of points in the graph ,m Represents the number of edges in the graph . (1≤ n≤100,0≤ m≤ n*(n-1)/2 )
Next m Rows give information about edges ,
Each line has two upper numbers x,y (1≤ x,y≤ n,x≠y)
Indication point x Sum point y There are edges between them . At most one edge of each pair of points is connected , Point itself will not have edge to itself .
Output
All in one line , If the given graph is considered to be an octopus, output "FHTAGN!"( No quotes ), Otherwise output "NO"( No quotes ).
Sample Input
6 6 6 3 6 4 5 1 2 5 1 4 5 4
Sample Output
FHTAGN!
The question : Give two numbers n,m, On behalf of n Nodes m side , And then follow m Two numbers per row a,b representative a Follow b Connected to a . Ask if the picture is an octopus , The shape of an octopus is that it has a ring and can form a connected graph . Yes, output FHTAGN!, Otherwise output NO.
Ideas : This problem only needs to satisfy two conditions to form an octopus ,1. Construct connected graph .2. There is only one ring . Using parallel search set to realize , Merge during input , If two nodes have a common ancestor, it means that a ring is formed , Then add one to the number of rings . And judge how many ancestors there are after the merger , If there is a ring and only one ancestor , It can form the shape of an octopus . The code is as follows :
#include<stdio.h>
#include<string.h>
int f[110];
int getf(int v)
{
if(f[v]==v)
return v;
else
{
f[v]=getf(f[v]);
return f[v];
}
}
int merge(int u,int v)
{
int t1,t2;
t1=getf(u);
t2=getf(v);
if(t1!=t2)
{
f[t2]=t1;
return 0;
}
return 1;
}
int main()
{
int i,x,y,n,m,r,sum;
while(~scanf("%d %d",&n,&m))
{
r=0;
sum=0;
for(i=1; i<=n; i++)
f[i]=i;
for(i=0; i<m; i++)
{
scanf("%d %d",&x,&y);
if(merge(x,y)==1)
r++;
}
for(i=1; i<=n; i++)
{
if(f[i]==i)
sum++;
}
if(sum==1&&r==1)
printf("FHTAGN!\n");
else
printf("NO\n");
}
return 0;
}
边栏推荐
- Devops Basics: Jenkins deployment and use (I)
- Little artist huangxinyang was invited to participate in the Wuhan station of children's unit of Paris Fashion Week
- 安装nrm后,使用nrm命令报错internal/validators.js:124 throw new ERR_INVALID_ARG_TYPE(name, ‘string‘, value)
- Two tips for block level elements
- The preliminary round of the sixth season of 2022 perfect children's model Foshan competition area came to a successful conclusion
- [introduction to SQL in 10 days] day5+6 consolidated table
- 关于在cmd中MySQL不能插中文数据的原因
- 【学习笔记】模拟
- 解决npm ERR! Unexpected end of JSON input while parsing near问题
- A - Bi-shoe and Phi-shoe
猜你喜欢

Idea related issues

B_QuRT_User_Guide(28)

城联优品向英德捐赠抗洪救灾爱心物资

The maximum number of Rac open file descriptors, and the processing of hard check failure

Wasmedge 0.10.0 release! New plug-in extension mechanism, socket API enhancement, llvm 14 support

Set the encoding of CMD to UTF-8

匿名页的反向映射

PLSQL installation under Windows

第六届智能家居亚洲峰会暨精品展(Smart Home Asia 2022)将于10月在沪召开

Login common test case
随机推荐
Love analysis released the 2022 love analysis · it operation and maintenance manufacturer panorama report, and an Chao cloud was strongly selected!
Redis deployment under Linux & redis startup
A - Bi-shoe and Phi-shoe
B_ QuRT_ User_ Guide(30)
Children's unit of 2022 Paris fashion week ended successfully at Wuhan station on June 19
Understanding of CUDA, cudnn and tensorrt
Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
Anniversary party
Build an integrated kubernetes in Fedora
NPM clean cache
B_QuRT_User_Guide(28)
【学习笔记】模拟
CloudCompare&PCL 点云裁剪(基于封闭曲面或多边形)
【Go ~ 0到1 】 第二天 6月25 Switch语句,数组的声明与遍历
Why MySQL cannot insert Chinese data in CMD
After installing NRM, the internal/validators js:124 throw new ERR_ INVALID_ ARG_ TYPE(name, ‘string‘, value)
js取整的小技巧
Kubernetes notes and the latest k3s installation introduction
Loss损失函数
匿名页的反向映射