题意:

给定一幅无向图, 求出图的割点。

割点模板:http://www.cnblogs.com/Jadon97/p/8328750.html

分析:

输入有点麻烦, 用stringsteam 会比较简单

#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#include<string>
#include<sstream>
#include<map>
#include<stack>
#include<vector>
#include<algorithm>
#include<cmath>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define _rep(i,a,b) for(int i = a; i <= b; i++)
using namespace std;
const int maxn = ;
vector<int> G[maxn];
int n, Index, root, ans;
int dfn[maxn], low[maxn], cut[maxn];
void tarjan(int u, int father){
dfn[u] = Index;
low[u] = dfn[u];
Index++;
int child = ;
for(int i = ; i < G[u].size(); i++){
int v = G[u][i];
if(!dfn[v]){
child++;
tarjan(v, u);
low[u] = min(low[v], low[u]);
if(low[v] >= dfn[u] && u != root) cut[u] = ;
if(u == root && child == ) cut[u] = ;
}else if(v != father){
low[u] = min(low[u], dfn[v]);
}
}
}
int main(){
ios::sync_with_stdio(false);
while(cin >> n && n){
Index = ;
memset(dfn, , sizeof(dfn));
memset(low, , sizeof(low));
memset(cut, , sizeof(cut));
_rep(i,,n) G[i].clear();
root = , ans = ;
string input;
while(getline(cin, input)){
if(input[] == '') break;
stringstream ss(input);
int u, v;
ss >> u;
while(ss >> v){
G[u].push_back(v);
G[v].push_back(u);
}
}
tarjan(,);
_rep(i,,n) if(cut[i]) ans++;
cout << ans << "\n";
}
return ;
}

POJ 1144 Network (求割点)的更多相关文章

  1. POJ 1144 无向图求割点

     学长写的: #include<cstdio>#include<cstdlib>#include<cmath>#include<iostream>#in ...

  2. POJ 1144 Network(割点)

    Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are c ...

  3. POJ 1144 Network(Tarjan求割点)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12707   Accepted: 5835 Descript ...

  4. POJ 1144 Network(无向图连通分量求割点)

    题目地址:id=1144">POJ 1144 求割点.推断一个点是否是割点有两种推断情况: 假设u为割点,当且仅当满足以下的1条 1.假设u为树根,那么u必须有多于1棵子树 2.假设u ...

  5. POJ 1144 Network(tarjan 求割点个数)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17016   Accepted: 7635 Descript ...

  6. poj 1144 Network 无向图求割点

    Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...

  7. poj 1144 Network(无向图求割顶数)

    题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...

  8. poj 1144 Network 图的割顶判断模板

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8797   Accepted: 4116 Descripti ...

  9. POJ 1523 SPF 求割点的好(板子)题!

    题意: 给个无向图,问有多少个割点,对于每个割点求删除这个点之后会产生多少新的点双联通分量 题还是很果的 怎么求割点请参考tarjan无向图 关于能产生几个新的双联通分量,对于每个节点u来说,我们判断 ...

  10. poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】

    题目地址:http://poj.org/problem?id=1144 题目:输入一个n,代表有n个节点(如果n==0就结束程序运行). 在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a ...

随机推荐

  1. hdu3926 Hand in Hand 同构图

    #include<cstring> #include<cstdio> #include<algorithm> using namespace std; ]; str ...

  2. April Fools Contest 2017 E

    Description Input The input consists of four lines, each line containing a single digit 0 or 1. Outp ...

  3. Jquery show()方法图解

    前两天面试的时候被问到了show()方法,当时回答的实在是太惨烈... 晚上看了一下,最简单的走法是直接移除行内样式的style属性. 如果这步走完了,元素还是隐藏的(display为none),元素 ...

  4. HDU 2828 Lamp 二分图的最大匹配 模型题

    http://acm.hdu.edu.cn/showproblem.php?pid=2828 给定n个灯,m个开关,使得每栈灯亮,前提是控制这栈灯的开关的状态是其中一个.(题目应该都看得懂) 其实我想 ...

  5. C. Quiz 贪心 + 数学

    http://codeforces.com/problemset/problem/337/C 题意是给出n个题目,那个人答对了m道,然后如果连续答对了k道,就会把分数double 求最小的分数是什么. ...

  6. CZ-python01-06

    练习代码 练习代码 # Python注释 # 注释不是越多越好,对于一目了然的代码,不需要添加注释 # 对于复杂的操作,应该在操作开始填上若干行注释 # 对于不是一目了然的代码,应在其行尾添加注释(为 ...

  7. RHEL6.5---LVS(IP-TUN)

    实验环境: 主机名 IP  所需软件 master eth0==>192.168.30.160(RIP) eth0:1==>192.168.30.130(VIP) ipvsadm node ...

  8. Camera和 tris,verts的优化

    Unity的Camera组件有很多可调节的参数,当需要做优化的时候,stats面板中的tris和verts这两个重点项都与Camera组件的参数有很大关系,有些参数的意义Unity手册说得不够详细,经 ...

  9. AJPFX的内存管理小结

    管理范围:任何继承于 NSObject的对象原理:每一个对象都有引用计数器当使用alloc new 和 copy创建对象时引用计数器被设置为1给对象发送一条retain消息 ,引用计数器加1     ...

  10. Handler引起的内存泄露

    一般我都写handler的时候是这样的:   public class MyActivity extends Activity{ private final Handler myHandler = n ...