题目:Cthulhu

题意:就是让你找一个简单的环,而且这个环不需要经过所有的点,只需要经过某些点就可以了,如果存在输出 FHTAGN! ,否则输出NO。
思路:简单的环就是只存在一个环,不存在多种环的情况,所以这种情况下我们我可以判断n个点是否连通,然后在判断边数是否为n,为什么?假设只经过6个点5条边已经连通了这种情况就是一条相连的直线的那种情况,那么再多一个点,那么这个图就存在环,不要想的太复杂了。判断这些点是否相连,我们可以采用并查集或者dfs,用并查集或者dfs判断是否经过所有的点,如果经过所有的点并且边的个数为n那么就输出 FHTAGN! ,否则就输出"red">NO。
代码:dfs

#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相关推荐

  1. Codeforce 水题报告(2)

    又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...

  2. 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 ...

  3. 2017.5.28 codeforce h题思考记录

    并没有报codeforce  但有人想让我帮他看题,于是就做了 大概意思就是,给你200个空,让你在200个空中放字母,   再自己设计一个串,要求自己设计的这个串在这放着200个字母的串中作为子串出 ...

  4. 【CodeForce】559B Equivalent Strings 等效字符串

    [CodeForce]559B Equivalent Strings 等效字符串 B. Equivalent Strings time limit per test2 seconds memory l ...

  5. Codeforce题解:Shurikens

    题目链接:https://codeforces.com/contest/1413/problem/D 题干描述: Tenten runs a weapon shop for ninjas. Today ...

  6. CF103B Cthulhu 解题报告

    CF103B Cthulhu 解题报告 1 题目链接 传送门 2 题目大意 题目 : 克苏鲁 (什么玩意儿) 题目大意 : 给定一个 n n n个定点 m m m条边的无向图,问该图是否唯一存在一个环 ...

  7. Codeforces 103B. Cthulhu 并查集运用

    题目链接: 题面: ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to ...

  8. 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 ...

  9. 氰化物工作室的游戏Cthulhu,或最终获得VR支持

    在2017年E3的闭门会议中,记者们看到了氰化物工作室的"Cthulhu".这款游戏充分地融入了它的洛夫洛根的根基,给玩家一个探索神秘的机会,而这个神秘的结局可能会让他们彻底发疯. ...

最新文章

  1. 无线+传感技术将物联网推向云端
  2. atitit.人脸识别的应用场景and使用最佳实践 java .net php
  3. 【Android 插件化】Hook 插件化框架 ( 通过反射获取 “插件包“ 中的 Element[] dexElements )
  4. MapXtreme 操作地图时出现调用目标发生异常的解决方法--地图状态保存
  5. 每个程序员都应该经历一次软考
  6. python画二维数组散点图_Python散点图二维数组
  7. bzoj 4942: [Noi2017]整数
  8. 详解Windows消息分类以及WM_COMMAND与WM_NOTIFY的区别,以及模拟发送控件通知消息
  9. 简历要避开哪些坑,资深面试官告诉你!
  10. nodejs error Windows_NT 6.1.7601 21 error code ELIFECYCLE 22 error angular-adminlte-plugin@0.1.0
  11. command line
  12. 大家都在用这个神器分析数据,而你还只会Excel表头过滤?
  13. windows删除文件trustedinstaller权限
  14. Android Jetpack架构篇:Room
  15. SEO及SEM学习参考资源
  16. 实践材料1(感谢刘望的翻译)
  17. 怎样才能使呼叫中心创新变得更有价值
  18. vue打测试包和正式包的配置
  19. 双栈(Dual Stack)
  20. 【微信公众号开发】自我学习第二章:关注事件触发的自动回复

热门文章

  1. BIGEMAP离线数据包网盘下载地址:中国高清地图数据,中国高清谷歌数据 密码:1111
  2. AD20设计规则小结(Design Rules)
  3. Verilog 相等运算符之相等和全等
  4. 集成运放四种反馈组态的通俗理解
  5. axis=0 与 axis=1 的区分
  6. Google Play ASO 系列 - 尽力获得官方推荐
  7. 机器学习中的方差和偏差理解
  8. Linux中学教程(一)
  9. Unity3D编程之NGUI和UGUI比较
  10. 【ACMMM 2022】Learning Hierarchical Dynamics with Spatial Adjacency for Image Enhancement