本题大意:求一个无向图额割点的个数.

本题思路:建图之后打一遍模板.

 /*************************************************************************
> File Name: uva-315.network.cpp
> Author: CruelKing
> Mail: 2016586625@qq.com
> Created Time: 2019年09月06日 星期五 17时15分07秒
本题思路:就是求图中有多少个割点
************************************************************************/ #include <cstdio>
#include <iostream>
#include <sstream>
#include <cstring>
#include <string>
using namespace std; const int maxn = + , maxm = maxn * maxn + ;
int tot, head[maxn]; struct Edge {
int to, next;
} edge[maxm]; void init() {
memset(head, -, sizeof head);
tot = ;
} void addedge(int u, int v) {
edge[tot] = (Edge) {v, head[u]}; head[u] = tot ++;
edge[tot] = (Edge) {u, head[v]}; head[v] = tot ++;
} int n;
string str; int dfn[maxn], low[maxn], stack[maxn];
bool cut[maxn], instack[maxn];
int Index, top, cut_num; void tarjan(int u, int pre) {
dfn[u] = low[u] = ++ Index;
instack[u] = true;
stack[top ++] = u;
int son = ;
for(int i = head[u]; ~i; i = edge[i].next) {
int v = edge[i].to;
if(!dfn[v]) {
son ++;
tarjan(v, u);
if(low[u] > low[v]) low[u] = low[v];
if(pre != u && low[v] >= dfn[u]) {
cut[u] = true;
}
} else if(low[u] > dfn[v]) low[u] = dfn[v];
}
if(u == pre && son > ) {
cut[u] = true;
}
instack[u] = false;
top --;
} void solve() {
memset(dfn, , sizeof dfn);
memset(low, , sizeof low);
memset(cut, false, sizeof cut);
Index = top = cut_num = ;
for(int i = ; i <= n; i ++) {
if(!dfn[i]) tarjan(i, i);
}
for(int i = ; i <= n; i ++) if(cut[i]) cut_num ++;
printf("%d\n", cut_num);
} int main() {
int u, v;
while(~scanf("%d", &n) && n) {
init();
while(scanf("%d", &u)) {
if(u == ) break;
getline(cin, str);
stringstream ss;
ss << str;
while(ss >> v) addedge(u, v);
}
solve();
}
return ;
}

uva-315.network(连通图的割点)的更多相关文章

  1. uva 315 Network(无向图求割点)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. UVA 315 315 - Network(求割点个数)

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

  3. UVA 315 求连通图里的割点

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20837 哎 大白书里求割点的模板不好用啊,许多细节理解起来也好烦..还好找了 ...

  4. UVA - 315 Network(tarjan求割点的个数)

    题目链接:https://vjudge.net/contest/67418#problem/B 题意:给一个无向连通图,求出割点的数量.首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第 ...

  5. 无向图求割点 UVA 315 Network

    输入数据处理正确其余的就是套强联通的模板了 #include <iostream> #include <cstdlib> #include <cstdio> #in ...

  6. hrbustoj 1494(原题UVA 315 Network) 解题报告 tarjan求割点

    主要思路:使用tarjan选取一个根节点建立一个棵搜索树,判断一个点是割点的充分必要条件是,对于一个节点u如果他的孩子节点v的low值大于等于u的出生日期dfn值,进行下一步判断,如果u是我们选的根节 ...

  7. UVA 315 Network (模板题)(无向图求割点)

    <题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...

  8. Uva 315 Network 判断割点

    模板题,注意输出 #include <stdio.h> #include <string.h> #include <algorithm> #include < ...

  9. UVA 315 求割点 模板 Tarjan

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

随机推荐

  1. ESP8266 SPI通信

    设备与设备之间的通信往往都伴随着总线的使用,而用得比较多的就当属于SPI总线和I2C总线,而恰巧NodeMcu也支持这两种总线通信 1. SPI总线——SPI类库的使用 SPI是串行外设接口(Seri ...

  2. Springboot(2.0.0.RELEASE)+spark(2.1.0)框架整合到jar包成功发布(原创)!!!

    一.前言 首先说明一下,这个框架的整合可能对大神来说十分容易,但是对我来说十分不易,踩了不少坑.虽然整合的时间不长,但是值得来纪念下!!!我个人开发工具比较喜欢IDEA,创建的springboot的j ...

  3. Kotlin使用率达35%,Java要退位了?

    在今年的Google I/O大会上,关于Kotlin,Google只说了只言片语: 在过去一年里,有35%的专业Android开发者在使用Kotlin,其中95%的开发者都对Kotlin非常满意. 之 ...

  4. EF大数据插入

    _April给出代码: using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotati ...

  5. java+struts上传文件夹文件

    这里只写后端的代码,基本的思想就是,前端将文件分片,然后每次访问上传接口的时候,向后端传入参数:当前为第几块文件,和分片总数 下面直接贴代码吧,一些难懂的我大部分都加上注释了: 上传文件实体类: 看得 ...

  6. 运行roslaunch启动节点报错找不到节点

    报错信息: ERROR: cannot launch node of type [${package_name}/${package_name}_node]: can't locate node [$ ...

  7. BZOJ 2716 [Violet 3]天使玩偶 (CDQ分治、树状数组)

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2716 怎么KD树跑得都那么快啊..我写的CDQ分治被暴虐 做四遍CDQ分治,每次求一个 ...

  8. Spring Boot教程(十)异步方法测试

    测试 测试代码如下: @Component public class AppRunner implements CommandLineRunner { private static final Log ...

  9. pycharm selenium 安装firefox驱动和Google驱动教程

    一.下载Firefox浏览器或Google浏览器 下载渠道有很多,直接下载最新版的就可以了. 二.下载驱动 Firefox驱动 地址:https://github.com/mozilla/geckod ...

  10. DataList是外部传入的子项数据列表

    //定义适配器类public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>{ private C ...