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".这款游戏充分地融入了它的洛夫洛根的根基,给玩家一个探索神秘的机会,而这个神秘的结局可能会让他们彻底发疯. ...
最新文章
- Android怎么自定义listview布局,android – 如何将listView标头添加为自定义布局
- Eclipse安装spring tool suite(4.9.0版本)
- ECCV 2020 《Propagating Over Phrase Relations for One-Stage Visual Grounding》论文笔记
- Navicat导出表结构
- 云钉一体应用创新:音视频如何带来灵活高效的协同体验
- 《Java 高并发》03 线程的生命周期
- DB2行转列(多维度)
- mysql 去重后拼接_mysql学习笔记(三)—— 查询select
- java之正则表达式、日期操作
- 手机基于蓝牙JDY-31蓝牙模块与52单片机串口通信
- win10应用商店无法连接到服务器出错,解决win10应用商店无法登陆提示错误0x80070426的方法...
- sata接口 图解 定义_【sata硬盘三个接口】sata硬盘接口图解_sata硬盘接口电路
- Linux批量操作------mov转MP4
- 测试—分类【修改版】
- el-tree重写勾选逻辑,实现父子节点勾选不互相关联,选中父级自动勾选子集,选中子集不勾选父级
- win10将HTML动态做桌面壁纸,Win10 怎么制作动态界面壁纸
- 【Android】时钟动态图标的定制化
- Manjaro Linux使用必应图片桌面/锁屏壁纸,每天自动更换
- netty tcp空闲设置
- iOS中的5款小众黑科技APP!用了都舍不得卸载!