题目链接:https://vjudge.net/problem/UVA-315

题目:求割点。

 #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; const int N = ;
int n,tim,tot,root = ;
int head[N],dfn[N],low[N],poi[N];
struct node{
int to;
int nxt;
}e[N*N]; void init(){
for(int i = ; i <= n; ++i){
head[i] = -;
dfn[i] = poi[i] = ;
}
tim = tot = ;
} inline void add(int u,int v){
e[tot].to = v;
e[tot].nxt = head[u];
head[u] = tot++;
} void tarjan(int now,int pre){
dfn[now] = low[now] = ++tim;
int to,son = ;
for(int o = head[now]; ~o; o = e[o].nxt){
to = e[o].to;
if(to == pre) continue; //处理无向图的双向边问题
if(!dfn[to]){
++son;
tarjan(to,now);
low[now] = min(low[now],low[to]);
//割点条件1
if(now != root && dfn[now] <= low[to]) poi[now] = ;
}
else if(low[now] > dfn[to]) low[now] = dfn[to];
}
//割点条件2
if(now == root && son >= ) poi[now] = ;
} int main(){ int u,v;
char ch; while(~scanf("%d",&n) && n){
init(); while(~scanf("%d",&u) && u){
while(~scanf("%d%c",&v,&ch)){
add(u,v); add(v,u);
if(ch == '\n') break;
}
}
tarjan(,);
int ans = ;
for(int i = ; i <= n; ++i)
if(poi[i]) ++ans; printf("%d\n",ans);
} return ;
}

kuangbin专题 专题九 连通图 Network UVA - 315的更多相关文章

  1. [kuangbin带你飞]专题九 连通图B - Network UVA - 315

    判断割点的性质: 如果点y满足 low[y]>=dfn[x] 且不是根节点 或者是根节点,满足上述式子的有两个及其以上. 就是割点 如果是起点,那么至少需要两个子节点满足上述条件,因为它是根节点 ...

  2. B - Network - uva 315(求割点)

    题意:给一个无向连通图,求出割点的数量. 首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第一个数字代表后面的都和它存在边,0表示行输入的结束(很蛋疼的输入方式). 分析:割点的模板题 ...

  3. Network UVA - 315(求割点)

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...

  4. Network UVA - 315 无向图找割点

    题意: 给你一个无向图,你需要找出来其中有几个割点 割点/割项: 1.u不为搜索起点,low[v]>=dfn[u] 2.u为搜索起点,size[ch]>=2 3.一般情况下,不建议在tar ...

  5. [kuangbin带你飞]专题九 连通图

        ID Origin Title   76 / 163 Problem A POJ 1236 Network of Schools   59 / 177 Problem B UVA 315 Ne ...

  6. 「kuangbin带你飞」专题十九 矩阵

    layout: post title: 「kuangbin带你飞」专题十九 矩阵 author: "luowentaoaa" catalog: true tags: mathjax ...

  7. UVA 315 求割点 模板 Tarjan

    D - D Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

  8. kuangbin专题 专题九 连通图 POJ 3694 Network

    题目链接:https://vjudge.net/problem/POJ-3694 题目:给定一个连通图,求桥的个数,每次查询,加入一条边,问加入这条边后还有多少个桥. 思路:tarjan + 并查集 ...

  9. kuangbin专题 专题九 连通图 POJ 1236 Network of Schools

    题目链接:https://vjudge.net/problem/POJ-1236 题目:有向图,有若干个连通图,点之间有单向边边就可以单向传递信息,问: (1)至少需要发送几份信息才能使得每个点都传递 ...

随机推荐

  1. 使用Beautiful Soup爬取猫眼TOP100的电影信息

    使用Beautiful Soup爬取猫眼TOP100的电影信息,将排名.图片.电影名称.演员.时间.评分等信息,提取的结果以文件形式保存下来. import time import json impo ...

  2. shell-删除指定时间前的文件

    需要配合find和rm两个命令完成 显示20分钟前的文件: find /home/prestat/bills/test -type f -mmin +20 -exec ls -l {} \; 删除20 ...

  3. Python之路Day09

    函数 将某个功能封装到一个空间中就是一个函数 减少重复代码 函数体中存放的时代码 定义函数 def len(): def 关键字 len 函数名 -- 变量名 ()格式规定 :语句结束 调用函数 函数 ...

  4. [SDOI2006] 仓库管理员的烦恼 - 二分图最大权匹配

    最小化代价,即最大化"本土"货物的数量 于是就是个二分图最大权匹配裸题 #include <bits/stdc++.h> using namespace std; #d ...

  5. c语言 printf格式化输出

    #include <iostream> #include<stdio.h> #include <cstring> using namespace std; int ...

  6. davinci入门必读

    http://www.usr.cc/forum.php/static/image/smiley/tiger/archiver/forum.php?mod=viewthread&action=p ...

  7. office2019与Visio2016不能共存解决办法

    我们电脑已经安装office2019,可是安装visio2016就会安装不了.只要两个软件同时安装就可以解决了,简单粗暴. 首先把电脑的offic或者visio都卸载了,删除干净. 然后先打开visi ...

  8. mysql内核测试&原理学习

    参考资料:https://www.cnblogs.com/f-ck-need-u/p/9001061.html#blog5

  9. [Codechef - AASHRAM] Gaithonde Leaves Aashram - 线段树,DFS序

    [Codechef - AASHRAM] Gaithonde Leaves Aashram Description 给出一棵树,树的"N"节点根植于节点1,每个节点'u'与权重a[ ...

  10. jQuery jqgrid

    1.写div <div class="ibox-content"> <div class="jqGrid_wrapper"> <! ...