Codeforces 263D Cycle in Graph【Dfs】
来源:互联网 发布:淘宝的售后服务是什么 编辑:程序博客网 时间:2024/05/22 12:47
题目大意:
给出N个点,M条无向边,保证现在每个点的度至少为K,让我们找到一个长度大于K+1的环。
思路:
直接Dfs即可,我们任意选择一个点进行Dfs,肯定会构成一个环出来,并且长度大于等于k+1。
Ac代码:
#include<stdio.h>#include<string.h>#include<vector>using namespace std;vector<int>mp[150000];int Len[150000],ans[150000];int n,m,k,cnt,ss,ee,ok;void Dfs(int u){ if(ok==1)return ; Len[u]=++cnt; ans[cnt]=u; for(int i=0;i<mp[u].size();i++) { int v=mp[u][i]; if(Len[v]) { if(Len[u]-Len[v]+1>=k+1) { ok=1; ss=v; ee=u; return ; } } else Dfs(v); }}int main(){ while(~scanf("%d%d%d",&n,&m,&k)) { ok=0; cnt=0; memset(Len,0,sizeof(Len)); for(int i=1;i<=m;i++) { int x,y;scanf("%d%d",&x,&y); mp[x].push_back(y); mp[y].push_back(x); } Dfs(1); printf("%d\n",Len[ee]-Len[ss]+1); for(int i=Len[ss];i<=Len[ee];i++) { printf("%d ",ans[i]); } printf("\n"); }}
阅读全文
0 0
- Codeforces 263D Cycle in Graph【Dfs】
- Codeforces 263 D. Cycle in Graph 环
- Codeforces 263 D. Cycle in Graph
- Codeforces 263 C. Circle of Numbers D. Cycle in Graph (dfs一般难度)
- cf#161-D-Cycle in Graph- dfs
- 263D - Cycle in Graph 图论 YY
- Codeforces Round #161 (Div. 2)-D. Cycle in Graph
- contest: Codeforces Round #161 (Div. 2), problem: (D) Cycle in Graph 图论
- Codeforces 246D Colorful Graph 【DFS】
- Codeforces Round #161 (Div. 2) D. Cycle in Graph(无向图中找指定长度的简单环)
- Cycle in Graph (coder)
- Codeforces 557D - Vitaly and Cycle (DFS染色)
- Codeforces 366D Dima and Trap Graph【二分+Dfs】
- Codeforces 841D Leha and another game about graph(dfs)
- codeforces 723D. Lakes in Berland [DFS]【】
- CodeForces 723D Lakes in Berland DFS
- codeforces #311 557D D. Vitaly and Cycle (dfs+图论判断判断构造奇环)
- Detect cycle in an undirected graph
- 级联下拉选,动态生成<option>标签实现,以及第二个下拉选无法显示问题
- 有趣的Linux命令
- sublime-text3 2017最新3143版可用注册码
- JAVA面向对象编程艺术与思想:打印日历1
- JS实现类似Android吐司样式(Toast样式)瞬时弹出对话框
- Codeforces 263D Cycle in Graph【Dfs】
- 第二章 身份验证
- Apache 服务器部署拥有域名的虚拟服务器vhost
- springmvc的contronller之间携带参数的跳转
- 【cesium】obj转换为gltf方法
- Android studio快速集成Kotlin
- JAVA时间字符串去空格、冒号和横杠
- linux下配置Java开发环境
- 2.CSS背景