poj3177 tarjan双联通缩点

POJ 3352 浅谈边双连通分量缩点 世界真的很大 刚刚才刷了一道边双连通的Tarjan 感觉不够,迅速再敲一道练手 然后1A,哇哇哇哇 虽然是一道水题,但我自己不会说出来233看题先:description: 给定图G,求最少加多少边可以成为双连通图。 input: The first line of input will consist of positive integers n and r, separated 阅读详情

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 descri_ption 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.
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.
Sample Input
7 7
1 2
2 3
3 4
2 5
4 5
5 6
5 7
Sample Output
2
Hint
Explanation of the sample:

One visualization of the paths is: 1 2 3 +—+—+ | | | | 6 +—+—+ 4 / 5 / / 7 + Building new paths from 1 to 6 and from 4 to 7 satisfies the conditions. 1 2 3 +—+—+
| |
| |
6 +—+—+ 4
/ 5 :
/ :
/ :
7 + - - - -
Check some of the routes:
1 – 2: 1 –> 2 and 1 –> 6 –> 5 –> 2
1 – 4: 1 –> 2 –> 3 –> 4 and 1 –> 6 –> 5 –> 4
3 – 7: 3 –> 4 –> 7 and 3 –> 2 –> 5 –> 7
Every pair of fields is, in fact, connected by two routes.

It’s possible that adding some other path will also solve the problem (like one from 6 to 7). Adding two paths, however, is the minimum.

要求至少加几条边才能使这个图连通的无向图双联通

其实关键在于先缩点,然后建立新的图再说其他的….

缩点和强连通分量一样的用栈缩点就可以…
然后建立新的图就是一颗树
因为这是个连通图所以只有一棵树
一半的叶子结点+1可以得出答案

#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
vector<int>tu[5001];
vector<int>xt[5001];
int dfn[5001],low[5001],clj,jc,die[5001],sd[5001];
bool mmm[5001][5001],ppp[5001][5001];
stack<int>ss;
void tarjan(int dian,int ba)
{
    dfn[dian]=low[dian]=++clj;
    die[dian]=ba;
    ss.push(dian);
    //int jiance=0;
    //if(tu[dian].size()>1)jiji[dian]++;
    for(int a=0;a<tu[dian].size();a++)
    {
        if(!dfn[tu[dian][a]])
        {
    //      jiance=1;
            tarjan(tu[dian][a],dian);
            low[dian]=min(low[dian],low[tu[dian][a]]);
        }
        else if(ba!=tu[dian][a])
        {
            if(low[dian]>=low[tu[dian][a]])
            {
                low[dian]=low[tu[dian][a]];
            }
        }
    }
    if(low[dian]==dfn[dian])
    {
        jc++;
        for(;;)
        {
            int ww=ss.top();
            ss.pop();
            sd[ww]=jc;
            if(ww==dian)break;
        }
    }
    //if(!jiance)yezi[dian]=1;
}
int main()
{
    int n,m;
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
//  memset(yezi,0,sizeof(yezi));
    memset(die,0,sizeof(die));
//  memset(jiji,0,sizeof(jiji));
    memset(ppp,0,sizeof(ppp));
    clj=0,jc=0;
    cin>>n>>m;
    int q,w;
    for(int a=1;a<=m;a++)
    {
        scanf("%d%d",&q,&w);
        if(mmm[q][w])continue;
        tu[q].push_back(w);
        tu[w].push_back(q);
        mmm[q][w]=mmm[w][q]=1;
    }
    tarjan(1,0);
//  for(int a=1;a<=n;a++)cout<<sd[a]<<" ";
//  cout<<endl;
    for(int a=1;a<=n;a++)
    {
        for(int b=0;b<tu[a].size();b++)
        {
            if(sd[a]==sd[tu[a][b]])continue;
            if(ppp[sd[a]][sd[tu[a][b]]])continue;
            ppp[sd[a]][sd[tu[a][b]]]=ppp[sd[tu[a][b]]][sd[a]]=1;
            xt[sd[a]].push_back(sd[tu[a][b]]);
            xt[sd[tu[a][b]]].push_back(sd[a]);
        }
    }
    int ye=0;
    for(int a=1;a<=jc;a++)
    {
        if(xt[a].size()==1)ye++;
    }
    cout<<(ye+1)/2<<endl;
    return 0;
}
POJ3352-Road Construction 【Tarjan-边双连通分量-缩点】 POJ3352-Road Construction 【Tarjan-边双连通分量-缩点】 解题报告+AC代码 http://hi.csdn.net/!s/0T8UO5 附:我所有的POJ解题报告链接 . http://blog.csdn.net/lyy289065406/article/details/6642573 立即下载

相关推荐

[LaTeX] 调整参考文献的格式(References),包括作者名缩写,行距,字体,引用顺序等等

在此记录我对LaTeX中参考文献references的尝试,主要涵盖如题几个方面。

the Blog of 等不到天亮丶等时光 4万+

bzoj1718 Redundant Paths(桥,tarjan边双缩点)

首先tarjan把边双都缩成一个点,这样我们就得到了一棵树。 如何把这棵树加最少的边变成边双呢? 统计出树中度为1的节点的个数,即为叶节点的个数,记为leaf。则至少在树上添加(leaf+1)/2条边,就能使树达到边二连通,所以至少添加的边数就是(leaf+1)/2。具体方法为,首先把两个最近公共祖先最远的两个叶节点之间连接一条边,这样可以把这两个点到祖先的路径上所有点收缩到一起,因为一个形成...

Icefox的博客 404

Windows安装ros2(Jazzy版本+win10/win11)-1.配置windows终端

更高版本的terminal可能设置里更加丰富, 有默认以管理员身份启动的选项等,可自行配置。打开微软应用商店, 在其中搜索并下载 Terminal 即可(注意别挂梯子)下载并安装, 安装的位置自行替换,建议别放到系统盘中。点击任务栏中的搜索, 输入store。

weixin_48398592的博客 1464

Tarjan缩点/边双/点双

文章目录代码实现实际应用1.有向图另外:对于缩点之后的DAG的处理2.无向图求法细节细节:目录:1.「POJ 3694」Network2.「2019 ICPC 横滨站」3. P3225 [HNOI2012]矿场搭建4. 一本通 分离的路径 代码实现 所以其实就三个玩意 1.dfn[],low[],indx 2.stack<int>s,bool pd[] 3.scc[],scnt,col[]等我们要求的信息 变量名 用处 dfn 记录当前已经访问了几个节点 scc

xajd1906的博客 807

保姆级教程:在Ubuntu 20.04上搞定pybind11,解决‘找不到头文件’的坑

本文提供了一份详细的Ubuntu 20.04下pybind11配置指南,重点解决常见的'找不到头文件'问题。从环境准备、安装策略到三种专业解决方案(修改CMakeLists.txt、环境变量方案、绝对路径包含),帮助开发者高效搭建C++与Python的桥梁。

weixin_28829325的博客 290

ATE测试基础——直流参数测试

芯片测试在发展过程中诞生了许多术语,初次接触的人大部分都会被绕晕。因此为方便广大读者理解,在开始介绍测试项之前,需要对测试领域的名词进行解释。还有部分较为抽象的内容,需要略作展开。DUT——Device Under Test,正在被测试的器件Pin——器件引脚,信号引脚分为输入,输出,三态和双向四类,负责与外界进行信息交互;电源引脚分为电源和地两类,结构与信号引脚不同,负责给器件内部运行和外部输出提供电平。输入:在外部信号和器件内部逻辑之间起缓冲作用的信号输入通道;

你骄傲地飞远的博客 1万+

无向图缩点:tarjan点双与边双缩点(模板)

e-DCC边双缩点:(用之前记得init) cnt1是从2开始的 const int N=1e4+100; const int M=1e5+100; struct Egde { int to,next; }edge1[M],edge2[M]; int head1[N],head2[N],low[N],dfn[N],c[N],num,cnt1,cnt2,dcc,n,m; bool br...

Falcon的博客 2661

基于Apache MINA SSHD配置及应用

Apache MINA SSHD是一个基于Java的开源SSH服务器/客户端实现,支持SSH2协议,提供文件传输、shell访问等功能。该代码实现了一个SftpClientService服务类,封装了SFTP文件操作,包括读取文件(readOnce/readLines)和写入文件(writeOnce)等核心功能。通过SftpProperties配置类管理连接参数,并采用Builder模式创建SSH会话。主要特点包括:支持大文件分块传输、自动创建目录、严格的异常处理和...

流沙QuickSand 954

CSU2104: Extra Judicial Operation-Tarjan边双联通分量缩点两种方法-难受的bug

(有任何问题欢迎留言或私聊 题目链接:CSU2104 题面:2017年南太平洋某区域赛题 The Suitably Protected Programming Contest (SPPC) is a multi-site contest in which contestants compete at specified sites, which are linked by the ...

打过ICPC/CCPC,学习ACM算法,Linux内核,Openharmony,加油努力开心珍惜 740

1、vectorCast单元测试常用操作

进入软件主页面,点击file,选择set working directory,随便选择一个保存该项目的目录即可。

weixin_59334478的博客 2161

【27】软考软件设计师——数据流图(DFD)补全题满分精讲|下午15分大题深度拆解

本文是《软件设计师·50讲通关|从零基础到工程师职称》专栏第27篇,深度精讲**下午案例题第1道必考大题:数据流图(DFD)补全**,该题单题分值高达**12 ~ 15分**,是整张试卷最稳的保底得分大题。我结合多年备考复盘与真题阅卷规则,超详细拆解DFD四大核心元素标准定义、机考绘图规范、三层分层逻辑、**父图子图平衡刚性扣分规则**,升级强化版「DFD满分补全三步法」;复刻历年高频真题完整流程,拆解缺失数据流定位、实体/存储辨析、平衡改错、文字需求对照全流程,配套**阅卷满分答题话术、机考避坑细则

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 629

poj 3177 双联通缩点

/*** 双联通缩点,再加几条边能使原图成为全部双联通 和强联通的区别在于,一个是有向图,一个是无向图 此题,原题连通 ***/ #include #include #include #include using namespace std; const int M = 10008; int low[M],t,dfs[M],instack[M],odd[M],index,bet,cn,stack

wyl_zheyang的专栏 545

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

poj 3177 Redundant Paths (边双联通分量+缩点)

/* * this code is made by LinMeiChen * Problem: * Type of Problem: * Thinking: * Feeling: */ #include #include #include #include #include #include #include #include #include #include using namespace s

ACM之梦 578

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

【边双连通 && 加几条边变成边双连通】POJ - 3177 Redundant Paths

Problem Description 输入n个点,m条边,边有重复,问你最少添加几条边,可以使得任意两个点,至少有两条不同的路径到达。其实就是问你最少添加几条边,使得图变成边双连通 思路: 卡了挺久的,就因为有重边,还以为是自己的代码错误。求边双连通的姿势不对。既然有重边,缩点(边双连通缩点)后 判断度得思考思考,有两种方法,一种是用邻接矩阵存边,这样重边就没事了,第二种方法就是,有桥就代

ACMer 梁剑锋 的博客 575

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Tarjan&LCA题集

【HDU】 [强连通]: 1269  迷宫城堡 判断是否是一个强连通★ 2767Proving Equivalences  至少加几条边让整个图变成强连通★ 3836 Equivalent Sets  至少加几条边让整个图变成强连通★ 1827    Summer Holiday  传递的最小费用★★ 3072    Intelligence System  传递的最小费用★★ 38

嗯。 1154

Tarjan&LCA题集【夏天的风】

【HDU】 [强连通]: 1269  迷宫城堡 判断是否是一个强连通★ 2767Proving Equivalences  至少加几条边让整个图变成强连通★ 3836 Equivalent Sets  至少加几条边让整个图变成强连通★ 1827    Summer Holiday  传递的最小费用★★ 3072    Intelligence System  传递的最小费用★★ 38

671coder的专栏 5457

[点bcc] 点双连通分量缩点建图图示

Mr_Alice的博客 1081

点双连通模版 求割点,点双缩点

两种缩点的模版

九野的博客 2128

双连通分量+缩点

It's almost summer time, and that means that it's almost summer construction time! This year, the good people who are in charge of the roads on the tropical island paradise of Remote Island would like...

qq_40859951的博客 1199

双联通缩点+二分图

  Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, and drinking with the other knights are fun things to do. Therefore, it is not very surprising ...

qq_40859951的博客 180

[POJ 3177]Redundant Paths[边双连通][Tarjan][缩点]

题目链接:[POJ 3177]Redundant Paths[边双连通][Tarjan][缩点] 题意分析: 给出一幅含有重边的无向图,问至少连多少条边,使得图中任意两个点u、v都有u->v的路径,和v->u的路径,且两者没有相同的边。 解题思路: 任意一个边双连通子图中两点是任意可达的,这样我们可以把这样的一个边双连通子图缩成一个点。将原图所有的双连通子图缩成一个点后,新图就是一棵树了,

闲停 514

双连通缩点 POJ 1515

B - 双连通 Time Limit:1000MS    Memory Limit:10000KB    64bit IO Format:%I64d & %I64u SubmitStatus Description According to the Automobile Collision Monitor (ACM), most fatal traffic accident

_rabbit的专栏 1545

Tarjan算法——边双和点双

边双连通分量 边双连通图:如果一个无向连通图中,没有割边,那么这个无向连通图就是一个边双连通图。 一个无向图的极大边双连通子图就是它的其中一个边双连通分量。 我们要解释下这里“极大”的概念:如果一个连通子图G1G1G1是边双,那么不存在一个原图的子图G2G2G2既满足G1∈G2G1∈G2G1\in G2又满足G2是边双G2是边双G2是边双。 边双的“极大”不是指整个图范围内的最大,而是所有...

蒟蒻柴犬首相的博客 7137
上一篇: poj3694 LCA+并查集+tarjan求割边
下一篇: CodeForces741b
NineFailure
博客等级 码龄11年 22粉丝 317原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值