【题目链接】

点击打开链接

【算法】

Tarjan算法求割点

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 110
#define MAXM 10010 struct Edge
{
int to,nxt;
} e[MAXM]; int n,i,u,v,timer,ans,tot;
bool is_cut[MAXN];
int head[MAXN],low[MAXN],dfn[MAXN]; inline void add(int u,int v)
{
tot++;
e[tot] = (Edge){v,head[u]};
head[u] = tot;
}
inline void tarjan(int u,int fa)
{
int i,v,son = ;
dfn[u] = low[u] = ++timer;
for (i = head[u]; i; i = e[i].nxt)
{
v = e[i].to;
if (fa != v)
{
if (!dfn[v])
{
tarjan(v,u);
low[u] = min(low[u],low[v]);
if (low[v] >= dfn[u]) son++;
} else low[u] = min(low[u],dfn[v]);
}
}
if (u != && son) is_cut[u] = true;
else if (u == && son > ) is_cut[u] = true;
else is_cut[u] = false;
} int main()
{ while (scanf("%d",&n) != EOF && n)
{
tot = ;
timer = ;
ans = ;
for (i = ; i <= n; i++)
{
dfn[i] = low[i] = ;
head[i] = ;
is_cut[i] = false;
}
while (scanf("%d",&u) && u)
{
while (getchar() != '\n')
{
scanf("%d",&v);
add(u,v);
add(v,u);
}
}
tarjan(,-);
for (i = ; i <= n; i++)
{
if (is_cut[i])
ans++;
}
printf("%d\n",ans);
} return ; }

【POJ 1144】 Network的更多相关文章

  1. 【POJ 3694】 Network(割边&lt;桥&gt;+LCA)

    [POJ 3694] Network(割边+LCA) Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7971 ...

  2. 【poj 1988】Cube Stacking(图论--带权并查集)

    题意:有N个方块,M个操作{"C x":查询方块x上的方块数:"M x y":移动方块x所在的整个方块堆到方块y所在的整个方块堆之上}.输出相应的答案. 解法: ...

  3. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  4. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  5. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  6. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  7. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  8. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  9. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

随机推荐

  1. 零基础入门学习Python(32)--异常处理:你不可能总是对的

    知识点 即便Python程序的语法是正确的,在运行它的时候,也有可能发生错误.运行期检测到的错误被称为异常. 大多数的异常都不会被程序处理,都以错误信息的形式展现在这里: Python标准异常总结 序 ...

  2. [转]TOpenDialog

    转自:http://www.cnblogs.com/zhangzhifeng/archive/2011/08/04/2127395.html 1.TOpenDialog组件的典型用法“打开”对话框是用 ...

  3. Spring Boot 2 (二):Spring Boot 2 尝鲜-动态 Banner

    Spring Boot 2.0 提供了很多新特性,其中就有一个小彩蛋:动态 Banner,今天我们就先拿这个来尝尝鲜. 配置依赖 使用 Spring Boot 2.0 首先需要将项目依赖包替换为刚刚发 ...

  4. Atcoder regular Contest 073(C - Sentou)

    Atcoder regular Contest 073(C - Sentou) 传送门 每个人对开关的影响区间为a[i]--a[i]+t,因此此题即为将所有区间离散化后求所有独立区间的长度和 #inc ...

  5. jsp+servlet+mysql增删改查

    用的IntelliJ IDEA开发的,jdk1.8 1 首先是项目结构,如下图所示 2看各层的代码 首先是web.xml <?xml version="1.0" encodi ...

  6. 全文搜索(AC-1)-互联网信息过载问题

    什么是信息过载? 信息检索技术是什么? 信息过滤技术是什么?

  7. [HAOI2011]Problem b 题解

    题目大意: 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y)=k. 思路: 设f(k)为当1≤x≤n,1≤y≤m,且n≤m,使gcd(x,y)=k的数对 ...

  8. POJ 3264 RMQ问题 用dp解决

    #include <cstdio> #include <cstring> #include <iostream> using namespace std; ; #d ...

  9. [BZOJ2462] [BeiJing2011]矩阵模板(二维Hash)

    传送门 二维哈希即可. 注意质数选的大一些,不然会超时. 还有插入的时候不判重居然比判重要快.. ——代码 #include <cstdio> int main() { ; ") ...

  10. bzoj 3224 NOI2004郁闷的出纳员

    NOI2004郁闷的出纳员 2013年12月26日6,1818 输入描述 Input Description 第一行有两个非负整数n和min.n表示下面有多少条命令,min表示工资下界. 接下来的n行 ...