poj 1144 Network(无向图求割顶数)
题目链接:poj 1144
题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数。
直接上大白书上的模板即可,只是输入也有点卡人,我竟然傻傻的用手写的输入挂来处理,看了别人的博客才知道用 scanf("%s") 即可,因为 scanf("%s") 不会读入空格,再适当处理下即可。
我的代码是:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int N = ; vector<int> G[N];
int pre[N], low[N], dfs_clock;
bool iscut[N]; inline void add_edge(int from , int to) {
G[from].push_back(to);
G[to].push_back(from);
} int dfs(int u, int fa) {
int lowu = pre[u] = ++dfs_clock;
int child = ;
for(int i = ; i < G[u].size(); ++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] = ;
}
else if(pre[v] < pre[u] && v != fa)
lowu = min(lowu, pre[v]);
}
if(fa < && child == ) iscut[u] = ;
return low[u] = lowu;
} inline bool isline(const char &ch) {
return ch == '\n' || ch == '\r';
} #include<cctype>
bool eol;
inline void read(int &x) {
x = ;
eol = ;
char ch = getchar();
while(!isdigit(ch))
ch = getchar();
while(isdigit(ch)) {
x = x * + (ch - '');
ch = getchar();
}
if(isline(ch)) eol = ;
} int main() {
int n,x;
while(~scanf("%d",&n),n) {
for(int i = ; i < ; ++i)
G[i].clear();
memset(pre,,sizeof(pre));
memset(iscut,,sizeof(iscut));
dfs_clock = ; while() {
eol = ;
read(x);
if(!x) {
for(int i = ; i <= n; ++i)
if(!pre[i]) dfs(i, -);
int ans = ;
for(int i = ; i <= n; ++i)
if(iscut[i]) ++ans;
printf("%d\n",ans);
break;
}
else {
int u = x;
while(!eol) {
read(x);
add_edge(u,x);
}
}
}
}
return ;
}
poj 1144 Network(无向图求割顶数)的更多相关文章
- poj 1144 Network 无向图求割点
Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...
- POJ 1144 Network(无向图连通分量求割点)
题目地址:id=1144">POJ 1144 求割点.推断一个点是否是割点有两种推断情况: 假设u为割点,当且仅当满足以下的1条 1.假设u为树根,那么u必须有多于1棵子树 2.假设u ...
- poj 1144 Network 图的割顶判断模板
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8797 Accepted: 4116 Descripti ...
- poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】
题目地址:http://poj.org/problem?id=1144 题目:输入一个n,代表有n个节点(如果n==0就结束程序运行). 在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a ...
- POJ 1144 Network (求割点)
题意: 给定一幅无向图, 求出图的割点. 割点模板:http://www.cnblogs.com/Jadon97/p/8328750.html 分析: 输入有点麻烦, 用stringsteam 会比较 ...
- POJ 3694 Network(无向图求桥+重边处理+LCA)
题目大意: 给你一个无向图,然后再给你一个Q代表有Q次询问,每一次加一条边之后还有几座桥.在这里要对重边进行处理. 每次加入一条边之后,在这条搜索树上两个点的公共祖先都上所有点的桥都没了. 这里重边的 ...
- [poj 1144]Network[Tarjan求割点]
题意: 求一个图的割点. 输入略特别: 先输入图中点的总数, 接下来每一行首先给出一个点u, 之后给出一系列与这个点相连的点(个数不定). 行数也不定, 用0作为终止. 这样的输入还是要保证以数字读入 ...
- POJ 1144 Network(无向图的割顶和桥模板题)
http://poj.org/problem?id=1144 题意: 给出图,求割点数. 思路: 关于无向图的割顶和桥,这篇博客写的挺不错,有不懂的可以去看一下http://blog.csdn.net ...
- 图论(无向图的割顶):POJ 1144 Network
Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. ...
随机推荐
- 【转】MYSQL入门学习之四:MYSQL的数据类型
转载地址:http://www.2cto.com/database/201212/175536.html 一.整型 www.2cto.com 整数类型是数据库中最基本的数据类型 ...
- Ajax中GET和POST的区别
Get方式: 用get方式可传送简单数据,但大小一般限制在1KB下,数据追加到url中发送(http的header传送),也就是说,浏览器将各个表单字段元素及其数据按照URL参数的格式附加在请求行中的 ...
- ssh 配置自动登录
假定 机器A 连接至 机器B . 1. 在机器A上,生成RSA秘钥对 ssh-keygen -t rsa 期间passphrase不输入密码.默认生成文件至 ~/.ssh/ -rw------- we ...
- CentOS 安装Redis
redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcached类似,但很大程度补偿了memcached的不足,它支持存储的value类型相对更多,包括strin ...
- AIM Tech Round 3 (Div. 2) A
Description Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Ko ...
- Educational Codeforces Round 16 C
Description Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column ...
- 查看centos是多少位的系统命令
打开命令行 运行下面命令 uname -i 如果是64位系统会显示x86_64 如果显示的是i386则是系统是32位
- 编译android源码官方教程(5)编译完之后刷机、编译fastboot
Running Builds IN THIS DOCUMENT Building fastboot and adb Booting into fastboot mode Unlocking the b ...
- linux 切换多个jdk脚本
1,编写脚本 jdkswitch.sh #!/bin/sh # usage: . this_file [argvs] openjdk7_home=/usr/lib/jvm/java--openjdk- ...
- 【Linux】CentOS设置静态IP(非动态获取IP)
在VMware上安装好Linux后,默认设置的动态IP,每次启动的IP都不同,远程连接挺费劲的. 于是,需要设置静态的IP,至少我从远程工具连接上去方便多了.另外,为了安装一些软件,也需要访问互联网. ...