BZOJ 1718 浅谈边双连通分量tarjan求法

寒假2019培训:双连通分量(点双+边双) 定义: 若一个无向连通图不存在割点,则称它为“点双连通图”。若一个无向连通图不存在割边,则称它为“边双连通图”。 无向图的极大点双连通子图称为“点双连通分量”,简记为“v-DCC”。无向连通图的极大边双连通子图被称为“边双连通分量”,简记为“e-DCC”。二者统称为“双连通分量”,简记为“DCC”。 边双联通分量 求法: 核心概念: 没有割边 割边只会把图分成两部分,对图中的点没有影响。 用... 阅读详情

这里写图片描述
世界真的很大
这几天学数论,算几,人都学傻了,什么FFT,高消的,会了有什么用呢?还不是死在没开long long上
这几天的亲身经历。。。
赶快做几道图论压压惊
看题先:
description:

In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rotten Apples. The cows are now tired of often being forced to take a particular path and want to build some new paths so that they will always have a choice of at least two separate routes between any pair of fields. They currently have at least one route between each pair of fields and want to have at least two. Of course, they can only travel on Official Paths when they move from one field to another. Given a description of the current set of R (F-1 <= R <= 10,000) paths that each connect exactly two different fields, determine the minimum number of new paths (each of which connects exactly two fields) that must be built so that there are at least two separate routes between any pair of fields. Routes are considered separate if they use none of the same paths, even if they visit the same intermediate field along the way. There might already be more than one paths between the same pair of fields, and you may also build a new path that connects the same fields as some other path.

N个点,M条边,问最少添加几条边使得图中任意两点互相到达且至少有两条完全不一样的路径。

input

* Line 1: Two space-separated integers: F and R * Lines 2..R+1: Each line contains two space-separated integers which are the fields at the endpoints of some path.

output

* Line 1: A single integer that is the number of new paths that must be built.

这题废话超级多,其实题目也就一句话
题目已经说出来了,任意两点之间至少两条完全不一样的路径,这里的完全不一样是指两条路径之间没有重合的部分,很明显就是在说边双连通分量
就是说给原图加多少条边可以使得其整个的变为一个边双连通图
所以首先想到把原图tarjan跑一遍边双连通分量缩一下点,就会得到一颗无向图的树,对于树的每一个度为1的点,两两连起来就好
而求边双连通分量和点双连通分量不同,和强连通分量的求法几乎一毛一样,唯一不同的是无向图和有向图的区别罢了
所以只需要在tarjan里面判断不走回头路就好
这道题有些特别,可能有重边,所以不能单单记录一下从那个点走来,还要记录是从那条边走来的
完整代码:

#include<stdio.h>
#include<algorithm>
#include<stack>
#include<cstring>
using namespace std;

struct edge
{
    int v,u,last;
}ed[100010];

stack <int> stk;

int n,m,num=0,mum=0,idx=0,cnt=0,ans=0;
int head[100010],ins[100010],dfn[100010],low[100010],vis[100010];
int place[100010],du[100010],fa[100010],tot[10010];

void add(int u,int v)
{
    num++;
    ed[num].u=u;
    ed[num].v=v;
    ed[num].last=head[u];
    head[u]=num;
}

void tarjan(int u)
{
    dfn[u]=low[u]=++idx;
    ins[u]=vis[u]=1;
    stk.push(u);
    for(int i=head[u];i;i=ed[i].last)
    {
        int v=ed[i].v;
        if(tot[i]==fa[u]) continue ;
        if(!vis[v])
        {
            fa[v]=tot[i];
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else
            low[u]=min(low[u],dfn[v]);
    }
    if(low[u]==dfn[u])
    {
        int t=-1;cnt++;
        while(t!=u)
        {
            t=stk.top();
            place[t]=cnt;
            stk.pop();
            ins[t]=0;
        }
    }
}

void ReBuild()
{
    for(int i=1;i<=num;i++)
    {
        int u=ed[i].u,v=ed[i].v;
        if(place[u]!=place[v])
            du[place[u]]++,du[place[v]]++;
    }
    for(int i=1;i<=cnt;i++)
        if(du[i]==2) ans++;
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        add(u,v);tot[num]=++mum;
        add(v,u);tot[num]=mum;
    }
    for(int i=1;i<=n;i++)
        if(!vis[i]) tarjan(i);
    ReBuild();
    printf("%d\n",(ans+1)/2);
    return 0;
}
/*
EL PSY CONGROO
*/

嗯,就是这样

BZOJ 3590 [双连通分量][状压DP] DescriptionDescription求一个包含所有节点的边双联通分量,并是边权和最小。n≤12n \le 12SolutionSolution注意到任意的一个边双连通分量都是由一条链和一个子双连通分量构成的,而且题中节点数n≤12n\le 12。考虑状压DP。令fSf_S表示点集为SS的双联通分量的权值的最小值。令hS,u,0/1h_{S, u, 0/1}表示边(u,v)(v∈S)(u,v) 阅读详情

相关推荐

BZOJ - 2574】[Poi1999] Store-Keeper(点双连通分量,求割点,记忆化bfs)

题干: 有一个仓库被分成n*m个矩形区域,如果两个区域有一条公共边,则被认为这两个区域相邻。包裹都放在一个区域中,剩余的区域或者空闲或者被集装箱占有,这是因为集装箱太重,仓库管理员不能将集装箱搬走。仓库管理员目是是要将包裹从开始的P区域移动到最后的K区域。他可以从空区域走到与之相邻的一个空区域。当仓库管理员走到与包裹相邻的区域时,它可以推动包裹,具体的推动方法如下所示: 读入一个储藏表...

xuanweiace的博客 914

poj 3177 求至少添加多少条边可以成为边-双连通图(有重边)

【题意】:给出一张无向连通图,求添加多少条边可以成为边-双连通图 【思路】:同3352 一样,求出边-双连通分量,缩点就成了一棵树,求这棵树里的出度为1 的点num 结果是(num-1)/2; 但是!! 这里和3352 哟一点不一样就是这里有重边,当有重边的时候,不同low值的两点可能属于同一个边-双连通分量 所以在构图的时候要...

weixin_30722589的博客 286

bzoj1718边双连通分量+贪心)

就是加点使图变成一个大的边双 先根据已有的边双缩点 会形成一棵树 贪心连叶子结点 答案=(num+1)/2(num+1)/2(num+1)/2 #include&amp;amp;lt;bits/stdc++.h&amp;amp;gt; using namespace std; int n , m , linkk[5100] ,t; int dfn[5100] , low[5100] , tt; int color[...

a1035719430的博客 662

POJ3177.Redundant Paths——增加多少条边使原图变为边双连通图

http://poj.org/problem?id=3177题目描述: 有n个牧场,Bessie 要从一个牧场到另一个牧场,要求至少要有2条独立的路可以走。现已有m条路,求至少要新建多少条路,使得任何两个牧场之间至少有两条独立的路。两条独立的路是指:没有公共边的路,但可以经过同一个中间顶点。分析:在同一个边双连通分量中,任意两点都有至少两条独立路可达,所以同一个边双连通分量里的所有点可以看做同一个

fsdcyr 634

POJ3177/BZOJ1718 Redundant Paths : Tarjan求桥+贪心

POJ3177/BZOJ1718 Redundant Paths : Tarjan求桥+贪心

YJSheep 3005

BZOJ1718分离的路径

边双题。 求的就是最少加几条边可以使一个图变成边双联通图。 首先tarjan求一下边双,缩完点变成一颗树,统计度数为1的点(无根树的叶子),把这个数算出来,设为x,则ans=(x+1)/2。 这个可以怎么理解呢?先分一下类,当x为偶数时,想让叶子节点边双联通就好像接到一条边,使之在一个环上(简单环肯定边双应该没问题吧),那么,我们任选两个叶子,将他们接到lca上就可以了,切路径上任...

bansi8227的博客 271

bzoj 1718 [Usaco2006 Jan] Redundant Paths 分离的路径

http://www.elijahqi.win/archives/3590 Description In order to get from one of the F (1 &lt;= F &lt;= 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the her...

Elijahqi 250

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

tarjan边双连通分量, 然后就是一棵树了, 可以各种乱搞...-------------------------------------------------------------------------------#include<cstdio>#include<cstring>#include<algorithm>using namespace...

weixin_30361753的博客 178

BZOJ1718: [Usaco2006 Jan] Redundant Paths 分离的路径

Description In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the herd are forced to cross near the Tr...

90

bzoj 1718: [Usaco2006 Jan] Redundant Paths 分离的路径

题面 题目描述 In order to get from one of the F (1 &lt;= F &lt;= 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rott...

蒟蒻柴犬首相的博客 398

bzoj1718】Redundant Paths 分离的路径

1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit:5 SecMemory Limit:64 MBSubmit:964Solved:503[Submit][Status][Discuss] Description In order to get from one of the F (1 <= F <...

weixin_30846599的博客 83

BZOJ1718: [Usaco2006 Jan] Redundant Paths 分离的路径

【题意】给定无向连通图,要求添加最少的边使全图变成边双连通分量。 【算法】Tarjan缩点 【题解】首先边双缩点,得到一棵树(无向无环图)。 入度为1的点就是叶子,两个LCA为根的叶子间合并最高效,直接将两个叶子并入双连通分量后建新图。 若没有两个LCA为根的叶子则往下换根。 ans=(num+1)/2。 猜想:如果要统计方案的话,就每次并后再次缩点,找一个非叶子作为根。 ...

weixin_34099526的博客 161

Tarjan算法求至少要添加几条边才能使无向连通图变为边双连通图。

转自:点击打开链接 给定一个连通的无向图G,至少要添加几条边,才能使其变为双连通图。          模型很简单,正在施工的道路我们可以认为那条边被删除了。那么一个图G能够在删除任意一条边后,仍然是连通的,当且仅当图G至少为双连通的。        PS:不要问我为什么不是3-连通、4-连通...人家题目问“至少添加几条边”好不...          显然,

Baoli1008的专栏 1794

无向连通图至少增加多少边形成双联通

poj3177 Redundant Paths Time Limit:1000MS Memory Limit:65536K Total Submissions:8558 Accepted:3712 Description In order to get from one of the F (1 &lt...

weixin_30341745的博客 239

无向图的双连通分量

文章目录定义例题冗余路径电力矿场搭建 定义 在一张连通的无向图中,对于两个点u和v,如果无论删去哪条边(只能删去一条)都不能使得它们不连通,则称u和v边双连通。 在一张连通的无向图中,对于两个点u和v,如果无论删去哪个点(只能删去一个,且不能删去u和v自己)都不能使得它们不连通,则称u和v点双连通。 边双连通具有传递性,即若x,y边双连通,y,z边双连通,则x,z边双连通。 点双连通不具有传递性。 割点:对于一个无向图,如果把一个点删除后这个图的极大连通分量数增加了,那么这个点就是这个图的割点。 割边:对于

HeartWine的博客 638

Tarjan三大算法之双连通分量双连通分量

https://blog.csdn.net/fuyukai/article/details/51303292定义: 对于一个连通图,如果任意两点至少存在两条点不重复路径,则称这个图为点双连通的(简称双连通);如果任意两点至少存在两条边不重复路径,则称该图为边双连通的。点双连通图的定义等价于任意两条边都同在一个简单环中,而边双连通图的定义等价于任意一条边至少在一个简单环中。对一个无向图,点双连通的极...

LP_Cong 6919
上一篇: BZOJ 3239 浅谈BsGs算法
下一篇: BZOJ 2732 浅谈计算几何之半平面交
BerryKanry
博客等级 码龄9年 63粉丝 163原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值