Codeforce Cthulhu
题目:Cthulhu
#include<bits/stdc++.h>
using namespace std;const int maxn = 205;//记住数组一定大小一定要开二倍,因为是双向建边
int h[maxn], e[maxn], ne[maxn], id = 0;
void add(int u, int v)//数组模拟链式前向星
{e[id] = v;ne[id] = h[u];h[u] = id++;
}
int n, m, u, v;
int vis[maxn];
void dfs(int u)//深搜
{vis[u] = 1;for(int i = h[u]; i != -1; i = ne[i]){int t = e[i];if(!vis[t]){dfs(t);}}
}
int main()
{cin>>n>>m;memset(h, -1, sizeof(h));for(int i = 0; i < m; i++){cin>>u>>v;add(u, v);add(v, u);}memset(vis, 0, sizeof(vis));dfs(1);int flag = 0;for(int i = 1; i <= n; i++)//判断是否有的边没有遍历{if(!vis[i])flag = 1;}if(flag == 0 && m == n)cout<<"FHTAGN!"<<endl;else cout<<"NO"<<endl;return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
int f[maxn];
int Find(int x){//并查集int p = x, tmp;while(x != f[x])x = f[x];while(p != x){tmp = f[x];f[x] = x;p = tmp;}return x;
}
int n, m;
void init(){for(int i = 1; i <= n; i++)f[i] = i;
}
int main(){cin>>n>>m;init();int u, v;for(int i = 1; i <= m; i++){cin>>u>>v;int fx, fy;fx = Find(u);fy = Find(v);if(fx != fy)f[fx] = fy;}int tmp = Find(1);int sum = 0;for(int i = 1; i <= n; i++){if(Find(i) == i)sum++;//判断有几个公共祖先,}if(sum == 1 && m == n)cout<<"FHTAGN!"<<endl;//如果只有一个祖先,那么整个图就是联通的else cout<<"NO"<<endl;
return 0;
}
Codeforce Cthulhu相关推荐
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- codeforce 1311 C. Perform the Combo 前缀和
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...
- 2017.5.28 codeforce h题思考记录
并没有报codeforce 但有人想让我帮他看题,于是就做了 大概意思就是,给你200个空,让你在200个空中放字母, 再自己设计一个串,要求自己设计的这个串在这放着200个字母的串中作为子串出 ...
- 【CodeForce】559B Equivalent Strings 等效字符串
[CodeForce]559B Equivalent Strings 等效字符串 B. Equivalent Strings time limit per test2 seconds memory l ...
- Codeforce题解:Shurikens
题目链接:https://codeforces.com/contest/1413/problem/D 题干描述: Tenten runs a weapon shop for ninjas. Today ...
- CF103B Cthulhu 解题报告
CF103B Cthulhu 解题报告 1 题目链接 传送门 2 题目大意 题目 : 克苏鲁 (什么玩意儿) 题目大意 : 给定一个 n n n个定点 m m m条边的无向图,问该图是否唯一存在一个环 ...
- Codeforces 103B. Cthulhu 并查集运用
题目链接: 题面: ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to ...
- A - Cthulhu CodeForces - 103B (并查集)
-Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for th ...
- 氰化物工作室的游戏Cthulhu,或最终获得VR支持
在2017年E3的闭门会议中,记者们看到了氰化物工作室的"Cthulhu".这款游戏充分地融入了它的洛夫洛根的根基,给玩家一个探索神秘的机会,而这个神秘的结局可能会让他们彻底发疯. ...
最新文章
- 无线+传感技术将物联网推向云端
- atitit.人脸识别的应用场景and使用最佳实践 java .net php
- 【Android 插件化】Hook 插件化框架 ( 通过反射获取 “插件包“ 中的 Element[] dexElements )
- MapXtreme 操作地图时出现调用目标发生异常的解决方法--地图状态保存
- 每个程序员都应该经历一次软考
- python画二维数组散点图_Python散点图二维数组
- bzoj 4942: [Noi2017]整数
- 详解Windows消息分类以及WM_COMMAND与WM_NOTIFY的区别,以及模拟发送控件通知消息
- 简历要避开哪些坑,资深面试官告诉你!
- nodejs error Windows_NT 6.1.7601 21 error code ELIFECYCLE 22 error angular-adminlte-plugin@0.1.0
- command line
- 大家都在用这个神器分析数据,而你还只会Excel表头过滤?
- windows删除文件trustedinstaller权限
- Android Jetpack架构篇:Room
- SEO及SEM学习参考资源
- 实践材料1(感谢刘望的翻译)
- 怎样才能使呼叫中心创新变得更有价值
- vue打测试包和正式包的配置
- 双栈(Dual Stack)
- 【微信公众号开发】自我学习第二章:关注事件触发的自动回复
热门文章
- BIGEMAP离线数据包网盘下载地址:中国高清地图数据,中国高清谷歌数据 密码:1111
- AD20设计规则小结(Design Rules)
- Verilog 相等运算符之相等和全等
- 集成运放四种反馈组态的通俗理解
- axis=0 与 axis=1 的区分
- Google Play ASO 系列 - 尽力获得官方推荐
- 机器学习中的方差和偏差理解
- Linux中学教程(一)
- Unity3D编程之NGUI和UGUI比较
- 【ACMMM 2022】Learning Hierarchical Dynamics with Spatial Adjacency for Image Enhancement