poj1144(求割顶模板题)
来源:互联网 发布:电视直播不卡软件 编辑:程序博客网 时间:2024/06/13 11:26
题意:求割顶个数,模板题不解释
代码如下:
#include<iostream>#include<algorithm>#include<stdio.h>#include<math.h>#include<cstring>#include<string>#include<vector>#define inf 0x3f3f3f3f#define pi acos(-1.0)#define eps 10e-6#define N 105using namespace std;char s[10000];vector<int> G[N];int pre[N],iscut[N],low[N];int dfs_clock;int dfs(int u,int fa){ int lowu = pre[u] = ++dfs_clock; int child = 0,len = G[u].size(); for(int i = 0; i < len; i++) { int v = G[u][i]; if(!pre[v]) { child++; int lowv = dfs(v,u); lowu = min(lowu,lowv); if(lowv >= pre[u]) iscut[u] = 1;//如果是u是割点则标记为1 } else if(pre[v] < pre[u] && v != fa) lowu = min(lowu,pre[v]); } if(fa < 0 && child == 1) iscut[u] = 0; low[u] = lowu;//可以不用low数组 return lowu;}int main(){ int n; while(scanf("%d",&n) && n) { getchar(); int i; for(i = 0; i <= n; i++) G[i].clear(); int u,v; while(scanf("%d",&u),u)//注意输入问题 { while (getchar()!='\n') { scanf("%d",&v); G[u].push_back(v); G[v].push_back(u); } } dfs_clock = 0; memset(iscut,0,sizeof(iscut)); memset(pre,0,sizeof(pre)); dfs(1,-1); int cnt = 0; for(i = 1; i <= n; i++) if(iscut[i] == 1) cnt++; printf("%d\n",cnt); } return 0;}
0 0
- poj1144(求割顶模板题)
- POJ1144-Network(割顶模板题)
- poj1144(求割点---kuangbin的模板)
- poj1144 割点模板
- 割点和桥问题 poj1144模板题
- poj1144 求割点 模版题
- poj1144-Network(求割点)
- poj1144(求割点)
- POJ1144
- poj1144
- POJ1144
- poj1144
- poj1144 求图的割点--模板
- [POJ1144]题面翻译-割点裸题
- poj1144( 求割点数)
- POJ1144--Network(Tarjan求割点)
- poj1144(求图中割点的个数)
- [POJ1144]Network(tarjan求割点)
- IOS学习笔记-4
- 黑马程序员 内部类和访问修饰符
- ZOJ 3813 Alternating Sum 树状数组
- 菜鸟之路--线性表__链式存储
- 【移动开发】Ken Burns特效的幻灯片
- poj1144(求割顶模板题)
- 程序设计基础9.9
- IOS响应式编程框架ReactiveCocoa(RAC)使用示例
- php验证码生成及验证
- Linux内核最新的连续内存分配器(CMA)——避免预留大块内存
- JAVAbean怎么调用
- Android Studio快捷键
- MySQL与Oracle 差异比较之一数据类型
- 大数亲和数对的求法 友元数对