【题目链接】

点击打开链接

【算法】

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 1010 int n,m,i,timer,tot;
int u[MAXN],v[MAXN],dfn[MAXN],low[MAXN],degree[MAXN],head[MAXN]; struct Edge
{
int to,nxt;
} e[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;
dfn[u] = low[u] = ++timer;
for (i = head[u]; i; i = e[i].nxt)
{
v = e[i].to;
if (v != fa)
{
if (!dfn[v])
{
tarjan(v,u);
low[u] = min(low[u],low[v]);
} else low[u] = min(low[u],dfn[v]);
}
}
}
inline void calc()
{
int i,cnt = ;
for (i = ; i <= m; i++)
{
if (low[u[i]] != low[v[i]])
{
degree[low[u[i]]]++;
degree[low[v[i]]]++;
}
}
for (i = ; i <= n; i++) cnt += (degree[i] == );
printf("%d\n",(cnt+)/);
} int main()
{ scanf("%d%d",&n,&m);
for (i = ; i <= m; i++)
{
scanf("%d%d",&u[i],&v[i]);
add(u[i],v[i]);
add(v[i],u[i]);
}
tarjan(,-);
calc(); return ;
}

【POJ 3352】 Road Construction的更多相关文章

  1. 【Aizu - 2249】Road Construction(最短路 Dijkstra算法)

    Road Construction Descriptions Mercer国王是ACM王国的王者.他的王国里有一个首都和一些城市.令人惊讶的是,现在王国没有道路.最近,他计划在首都和城市之间修建道路, ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. [Python3网络爬虫开发实战] 1.2.2-Selenium的安装

    Selenium是一个自动化测试工具,利用它我们可以驱动浏览器执行特定的动作,如点击.下拉等操作.对于一些JavaScript渲染的页面来说,这种抓取方式非常有效.下面我们来看看Selenium的安装 ...

  2. 集训第六周 数学概念与方法 概率 F题

    Submit Status Description Sometimes some mathematical results are hard to believe. One of the common ...

  3. 61. mybatic insert异常:BindingException: Parameter 'name' not found【从零开始学Spring B】

    mybatic insert异常:BindingException: Parameter 'name' not found [从零开始学习Spirng Boot-常见异常汇总] 异常信息如下: nes ...

  4. [POJ3463] Sightseeing(次短路 Heap + Dijkstra)

    传送门 用dijkstra比较好,spfa可能有的重复 dis[x][2]:dis[x][0]表示起点到x的最短路.dis[x][1]表示起点到x的次短路: tot[x][2]:tot[x][0]表示 ...

  5. 一个Java开发的Python之路----------------(一)

    最近开始学习Python了,主要是因为现在在给海航通过JAVA写CMDB运维管理平台,我就是作为唯一一个坐在运维屋里的开发,又当爹,又当妈,前端,后台,测试,设计,需求, 发布,统统一把抓!!在Git ...

  6. POJ 3169_Layout

    大早上水一发=.= 题意: n头牛按编号顺序站成一列,给定n头牛之间的位置关系,求出第n头牛和第一头牛之间的最大距离. 分析: 差分约束系统,这题不等式关系还是挺好找的.注意因为按照顺序排列,所以有d ...

  7. nginx: [emerg] unknown directive "聽" in D:\software03\GitSpace\cms\nginx-1.14.0/conf/nginx.conf:36

    nginx: [emerg] unknown directive "聽" in D:\software03\GitSpace\cms\nginx-1.14.0/conf/nginx ...

  8. easyUi 学习笔记 (二 ) 使用tabs 里datagridview 发送ajax请求 不访问后台的问题

    这个BUG 我花了一个半小时, 还是看不出哪里的问题,  于是就百度到这么一段话,我需要记住 <================================================= ...

  9. fastjson过滤器简单记录

    fastjson过滤器,该字段可以将转化的json字段遍历,方便实用 1 /** * 通用输出json * @param object * @return json字符串 */ public Stri ...

  10. Servlet的过滤器(Filter)

    以下内容引用自http://wiki.jikexueyuan.com/project/servlet/writing-filters.html: Servlet过滤器是Java类,可用于Servlet ...