poj 1523 SPF
2015-06-12 18:02
330 查看
求割点和块的个数。
相关定理及证明,大白书P313
相关定理及证明,大白书P313
#include<stdio.h> #include<cstring> #include<algorithm> using namespace std; int head[1005],cnt,p[1005],ans[1005],dfs_clock; struct E{ int to,next; }edge[2000]; inline void add(int u,int v) { edge[cnt].to=v; edge[cnt].next=head[u]; head[u]=cnt++; } int dfs(int u,int fa) { int lowu=p[u]=++dfs_clock,child=0; for(int i=head[u];~i;i=edge[i].next) { if(!p[edge[i].to]) { ++child; int lowv=dfs(edge[i].to,u); lowu=min(lowu,lowv); if(lowv>=p[u]) ++ans[u]; } else if(p[edge[i].to]<p[u]&&edge[i].to!=fa) lowu=min(lowu,p[edge[i].to]); } return lowu; } int main() { int i,n,x,y,ca=1; while(~scanf("%d",&x)&&x) { cnt=dfs_clock=0; memset(head,-1,sizeof(head)); memset(p,0,sizeof(p)); scanf("%d",&y); add(x,y); add(y,x); n=max(x,y); while(scanf("%d",&x)&&x) { scanf("%d",&y); add(x,y); add(y,x); n=max(n,max(x,y)); } printf("Network #%d\n",ca++); for(i=1;i<=n;++i) ans[i]=1; ans[1]=0; dfs(1,-1); bool flag=0; for(i=1;i<=n;++i) if(ans[i]>1) { flag=1; printf(" SPF node %d leaves %d subnets\n",i,ans[i]); } if(!flag) puts(" No SPF nodes"); puts(""); } return 0; }
相关文章推荐
- mouseover,mouseout和mouseenter,mouseleave
- 静态代码分析工具 Infer
- iOS Code Signing 学习笔记
- SpringMVC Controller 介绍
- WinpCap抓包 公开的免费的抓包驱动加开发包
- mac 把文件转成pdf格式
- Android开发者必须深入学习的10个应用开源项目
- Mybatis写mapper映射文件中的注意事项
- java 多线程编程三种实现方式
- 适配器模式
- iOS UICollectionView的使用(用storyboard和xib创建)
- 线程同步
- Odoo文档管理/知识管理应用实践 - 上传附件
- OS开发实践:用Swift和Core Animatoin创建圆形图片加载动画
- android,[游戏] 美女擦玻璃游戏源码
- 自有账户体系对接百度云推送必须要弄懂的问题
- SSH反向连接及Autossh
- LeetCode Invert Binary Tree
- outlook客户端打开后报证书错误
- git安装及git常用操作简介