[题目链接]

https://www.lydsy.com/JudgeOnline/problem.php?id=1718

[算法]

用Tarjan算法找出所有e-DCC(边-双联通分量),然后将这张图缩点,答案即为(缩点后的树的叶子节点的个数 + 1) / 2

[代码]

#include<bits/stdc++.h>
using namespace std;
#define MAXN 5010
#define MAXM 10010 struct edge
{
int to,nxt;
} e[MAXM << ]; int i,n,m,cnt,s,timer,tot;
int head[MAXN],u[MAXM],v[MAXM],low[MAXN],dfn[MAXN],belong[MAXN],degree[MAXN];
bool is_bridge[MAXM << ]; inline void addedge(int u,int v)
{
tot++;
e[tot] = (edge){v,head[u]};
head[u] = tot;
}
inline void tarjan(int u,int t)
{
int i,v;
dfn[u] = low[u] = ++timer;
for (i = head[u]; i; i = e[i].nxt)
{
v = e[i].to;
if (!dfn[v])
{
tarjan(v,i);
low[u] = min(low[u],low[v]);
if (low[v] > dfn[u])
is_bridge[i] = is_bridge[i ^ ] = true;
} else if (i != (t ^ )) low[u] = min(low[u],dfn[v]);
}
}
inline void dfs(int u)
{
int i,v;
belong[u] = cnt;
for (i = head[u]; i; i = e[i].nxt)
{
v = e[i].to;
if (!belong[v] && !is_bridge[i])
dfs(v);
}
} int main()
{ scanf("%d%d",&n,&m);
tot = ;
for (i = ; i <= m; i++)
{
scanf("%d%d",&u[i],&v[i]);
addedge(u[i],v[i]);
addedge(v[i],u[i]);
}
for (i = ; i <= n; i++)
{
if (!dfn[i])
tarjan(i,);
}
for (i = ; i <= n; i++)
{
if (!belong[i])
{
cnt++;
dfs(i);
}
}
for (i = ; i <= m; i++)
{
if (belong[u[i]] != belong[v[i]])
{
degree[belong[u[i]]]++;
degree[belong[v[i]]]++;
}
}
for (i = ; i <= cnt; i++) s += (degree[i] == );
printf("%d\n",(s + ) / ); return ; }

[BZOJ 1718] Redundant Paths的更多相关文章

  1. BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )

    tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...

  2. 【bzoj1718】Redundant Paths 分离的路径

    1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 964  Solve ...

  3. [Usaco2006 Jan] Redundant Paths 分离的路径

    1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1132  Solv ...

  4. POJ 3177 Redundant Paths(边双连通的构造)

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13717   Accepted: 5824 ...

  5. [双连通分量] POJ 3177 Redundant Paths

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13712   Accepted: 5821 ...

  6. tarjan算法求桥双连通分量 POJ 3177 Redundant Paths

    POJ 3177 Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12598   Accept ...

  7. [POJ3177]Redundant Paths(双联通)

    在看了春晚小彩旗的E技能(旋转)后就一直在lol……额抽点时间撸一题吧…… Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Tota ...

  8. poj 3177 Redundant Paths【求最少添加多少条边可以使图变成双连通图】【缩点后求入度为1的点个数】

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11047   Accepted: 4725 ...

  9. POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)

    POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...

随机推荐

  1. Canvas——基本入门

    基本概念 1.canvas 是 HTML5 提供的一个用于展示绘图效果的标签. canvas 原意画布, 帆布. 在 HTML 页面中用于展示绘图效果. 最早 canvas 是苹果提出的一个方案, 今 ...

  2. JS——scroll动画

    固定导航栏 1.计算导航栏到顶部的距离值 2.当scrollTop值大于这个距离值就添加定位,当小于距离值后解除定位 注意事项:当导航栏添加定位之后,导航栏就脱离了文档流,也就是不占位了,下面的盒子就 ...

  3. strut2 拦截器 使用

    拦截器是strut2里一个很振奋人心的应用.通过配置拦截器可以在action执行之前进行一些初始化或者是其他的操作,但是在action执行之后,返回结果就已经确定,结果是很难改变了(目前我还不知道怎么 ...

  4. HDU_1698_Just a Hook_线段树区间更新

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. c++/c DEBUG宏

    #cat log_debug.h #ifdef DEBUG int log_debug(const char *format, ...); #else int log_debug(const char ...

  6. jquery spa

    1.hashchange监听 2.根据url加载不同页面 $.ajax({ url:"/xx/xx.html" type:"get", dataType:&qu ...

  7. JAVA学习总结-常用数据结构

    java中集合框架其实就是数据结构的实现的封装; 参考资料:任小龙教学视频 1,什么是数据结构? 数据结构是计算机存储,组织数据的方式; 数据结构是指相互之间存在一种或多种特定关系的数据元素的集合; ...

  8. C#学习笔记_11_方法的隐藏和重写

    11_方法的隐藏和重写 方法的隐藏 需要使用到关键字:new 方法的重写 虚函数: 使用关键字virtual修饰的函数 虚函数可以被子类隐藏,也可以被子类重写 非虚函数只能被子类隐藏 关键字:over ...

  9. C#关键字详解第一节

    abstract:抽象类: 他表达对问题或者实际中的事物,对象等所设计出的抽象概念,比如一个灵感.生物等,这些都是抽像, 但是他们往往也有具体的指向,比如生物圈有人类,猴子,老虎等等,老虎和人类是实际 ...

  10. 【codeforces 508A】Pasha and Pixels

    [题目链接]:http://codeforces.com/contest/508/problem/A [题意] 让你在一个n*m的方格上给方格染色; 顺序给出染色的k个格子 如果在某一时刻 有一个2* ...