Round 2 A - Cthulhu CodeForces - 103B -图同构,DFS
题目链接:
http://codeforces.com/problemset/problem/103/B
大意:
判断图的形状是否为一个章鱼型(?)
由几棵树构成,树的根节点围成一个环。
思路:
只需判断一棵树内加一个环即可。
判断方法: 边数==顶点数 && 连通图
#include<bits/stdc++.h>
#define mem(s,t) memset(s,t,sizeof(s))
typedef long long ll;
using namespace std;
//#define LOCAL
int n,m;
const int MAXN =100+10;
int g[MAXN][MAXN];
int vis[MAXN];
int cnt=0;
void dfs(int x){vis[x]=1;cnt++;for(int i=1;i<=n;i++){if(!vis[i] && g[x][i]){dfs(i);}}
}
int main(){
#ifdef LOCALfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endifcin>>n>>m;mem(g,0);mem(vis,0);for(int i=0;i<m;i++){int x,y;cin>>x>>y;g[x][y]=g[y][x]=1;}dfs(1);if(n==m){if(cnt==m) puts("FHTAGN!");else puts("NO");}else puts("NO");return 0;
}
Round 2 A - Cthulhu CodeForces - 103B -图同构,DFS相关推荐
- 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 ...
- CodeForces 103B Cthulhu
http://codeforces.com/problemset/problem/103/B 找环,一个环 #include<bits/stdc++.h> using namespace ...
- Codeforces Round #316 (Div. 2) D. Tree Requests dfs序
题目链接: 题目 D. Tree Requests time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 Rom ...
- Codeforces Round #801 (Div. 2) D2(思维/dfs)
传送门 题意:给你一颗树,问最少取几点并且得知其与未知点x的距离可以确定树中任意x是哪个节点. 思考:观察可知,对于叶子节点,其兄弟节点到父节点所在的路径上都有点被取到时,不用取它也可以知道具体是哪个 ...
- Codeforces 103B Cthulhu
题意: 给你n个点m条边的无向图(无重边和自环),问你是否存在一个简单的环且环上的点都是某棵树的树根. 思路: 注意这句话:an undirected graph that can be repres ...
- Codeforces 103B. Cthulhu 并查集运用
题目链接: 题面: ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to ...
- Codeforces 103B - Cthulhu(并查集 找环和块)
传送门:https://codeforces.com/problemset/problem/103/B 题意: 给一个n个结点,m条边的无向图 判断给定图是否满足以下条件: 能被表示为有3个及以上的有 ...
- Codeforces Round #607 (Div. 2) E. Jeremy Bearimy dfs + 思维
传送门 文章目录 题意: 思路: 题意: 给你2∗k2*k2∗k个点的一棵树.定义GGG为任选kkk组不同的点,每组点的距离和的最小值.定义BBB为任选kkk组不同的点,每组点的距离和的最大值.让你求 ...
- Last Theorem CodeForces - 1325F(dfs树找最大环+思维)
It's the year 5555. You have a graph, and you want to find a long cycle and a huge independent set, ...
最新文章
- HttpServlet详解
- bitwarden自建服务器,BitWarden
- Android APP性能优化
- android 过滤格式,android Intent.setType() 过滤图片,返回所有的文件类型
- 摘要提取算法——本质上就是pagerank,选择rank最高的句子作为摘要,如果结合word2vec应该有非常好的效果...
- python编程少儿游戏编程_少儿编程课堂|python – 用游戏学编程
- Effective Java之EnumMap代替序数索引(三十三)
- 青岛智能院助力智慧城市 打造智能产业“黄埔军校”
- 小米跨界成立餐饮公司?其实就是新园区食堂...
- restframework 第一天
- 微软:SolarWinds 供应链攻击事件幕后黑手攻击全球24国政府
- Tricks(七)——list of lists 行和、列和的计算
- Android 热补丁之 Tinker 原理解析
- 常用字符对应ASCII码值
- Java实现百度贴吧自动签到器
- Unity 绳子效果 插件(Obi Rope )
- 抖音运营 | 10万赞的短视频如何打造?
- 一些实用高效的装机软件汇总
- Android 手机抓包
- github推送Please make sure you have the correct access rights and the repository exists.