hdu4612——Warm up

验证 helm Chart 的正确性 阅读详情

Warm up

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 3790    Accepted Submission(s): 862


Problem Description
  N planets are connected by M bidirectional channels that allow instant transportation. It's always possible to travel between any two planets through these channels.
  If we can isolate some planets from others by breaking only one channel , the channel is called a bridge of the transportation system.
People don't like to be isolated. So they ask what's the minimal number of bridges they can have if they decide to build a new channel.
  Note that there could be more than one channel between two planets.
 

Input
  The input contains multiple cases.
  Each case starts with two positive integers N and M , indicating the number of planets and the number of channels.
  (2<=N<=200000, 1<=M<=1000000)
  Next M lines each contains two positive integers A and B, indicating a channel between planet A and B in the system. Planets are numbered by 1..N.
  A line with two integers '0' terminates the input.
 

Output
  For each case, output the minimal number of bridges after building a new channel in a line.
 

Sample Input
  
4 4 1 2 1 3 1 4 2 3 0 0
 

Sample Output
  
0
 

Source
 

Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:   5065  5064  5062  5061  5060 
 

先 tarjan然后缩点得到一颗树,求树的直径就好了


#include <map>
#include <set>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

const int N = 200010;
const int inf = 0x3f3f3f3f;
const int M = 1000010;

struct node
{
    int next;
    int to;
    int id;
}edge[M], edge2[M];

bool vis[N];
bool flag[N];
int dist[N];
int head[N];
int head2[N];
int low[N];
int block[N];
int DFN[N];
bool instack[N];
stack<int>qu;
int br_cnt, n, m, end_p;
int tot, tot2, maxs, index, top, sccnum;

void addedge(int from, int to, int id)
{
    edge[tot].id = id;
    edge[tot].to = to;
    edge[tot].next = head[from];
    head[from] = tot++;
}

void addedge2(int from, int to)
{
    edge2[tot].to = to;
    edge2[tot].next = head2[from];
    head2[from] = tot++;
}

void init()
{
    index = 0;
    sccnum = 0;
    top = 0;
    tot = 0;
    tot2 = 0;
    maxs = 0;
    br_cnt = 0;
    end_p = 0;
    memset ( head, -1, sizeof(head) );
    memset (head2, -1, sizeof(head2) );
    memset ( low, 0, sizeof(low) );
    memset (DFN, 0, sizeof(DFN) );
    memset ( instack, 0, sizeof(instack) );
    memset ( flag, 0, sizeof(flag) );
    memset (vis, 0, sizeof(vis) );

}

void build()
{
    int u, v;
    while (!qu.empty() )
    {
        qu.pop();
    }
    for (int i = 1; i <= m; ++i)
    {
        scanf("%d%d", &u, &v);
        addedge(u, v, i);
        addedge(v, u, i);
    }
}

void tarjan(int u, int fa)  
{  
    qu.push(u);
    instack[u] = 1;
    DFN[u] = low[u] = ++index;  
    for (int i = head[u]; i != -1; i = edge[i].next)  
    {  
        int v = edge[i].to;  
        if (fa == edge[i].id)  
        {
            continue;
        }   
        if ( !instack[v] )  
        {  
            tarjan(v, edge[i].id);  
            low[u] = min(low[u], low[v]);  
            if (DFN[u] < low[v])
            {
                br_cnt++;
            }
        }  
        else 
        {
            low[u] = min(DFN[v], low[u]);
        }  
    }
    if (DFN[u] == low[u])
    {
        sccnum++;
        int v;
        while(1)
        {
            v = qu.top();
            qu.pop();
            instack[v] = 0;
            block[v] = sccnum;
            if(v == u)
            {
                break;
            }
        }
    }
}

void bfs(int s)
{
    queue<int>qu;
    while ( !qu.empty() )
    {
        qu.pop();
    }
    memset ( vis, 0, sizeof(vis) );
    qu.push(s);
    dist[s] = 0;
    vis[s] = 1;
    maxs = 0;
    while ( !qu.empty() )
    {
        int u = qu.front();
        qu.pop();
        for (int i = head2[u]; i != -1; i = edge2[i].next)
        {
            int v = edge2[i].to;
            if (!vis[v])
            {
                vis[v] = 1;
                dist[v] = dist[u] + 1;
                qu.push(v);
                if (maxs < dist[v])
                {
                    maxs = dist[v];
                    end_p = v;
                }
            }
        }
    }
}

void solve()
{
    for (int i = 1; i <= n; ++i)
    {
        if (DFN[i] == 0)
        {
            tarjan(i, -1);
        }
    } 
    for (int u = 1; u <= n; ++u)
    {
        for (int i = head[u]; i != -1; i = edge[i].next)
        {
            int v = edge[i].to;
            if (block[u] != block[v])
            {
                addedge2(block[u], block[v]);
            }
        }
    }
    bfs(1);
    bfs(end_p);
    printf("%d\n", br_cnt - maxs);
}

int main()
{
    while (~scanf("%d%d", &n, &m))
    {
        if (!n && !m)
        {
            break;
        }
        init();
        build();
        solve();
    }
    return 0;
}


【proteus】模拟串口和物理串口通讯 proteus提供了两种串口,一种是模拟的串口,还有一张是用软件仿真到硬件的物理串口。他们的区别就是:模拟串口只能在proteus内部进行通讯,但是物理可以通过软件映射到硬件上和单机或者串口软件通讯。 物理串口在元器件搜索COMPIM即可找到。 模拟串口在这里: PROTEUS仿真图: 物理串口COMPIM的设置: 模拟串口的设置: VSPD是一款虚拟串口软件,VSPD下载链接: 链接:https://pan.baidu.com/s/1AZygJCeWZfQTnxdCb_3TPg 提取码:12pm 阅读详情

相关推荐

当NetApp 7-mode遇到单控制器故障:HA模式手动修复全记录

本文详细记录了NetApp 7-mode存储系统在单控制器故障时的应急修复过程,包括HA配置重建、磁盘初始化和业务恢复等关键步骤。通过实战案例解析如何解决`VIA Interconnect is down`等典型问题,为企业级存储系统的高可用保障提供实用指南。

yolo5detector的博客 256

HDU - 4612 Warm up(缩点 边双连通)

HDU - 4612  题意+思路: 和之前的POJ - 3694类似,但是这个是求加了一条边之后桥的最小值。 那么我们的做法就可以: 1.求边双连通分支并缩点。 2.把桥加回来统计桥的数量num,找这棵树上的最长的直径l; ans = num-l; 这里用到的处理重边的办法就是tarjan传递的是边的下标,然后判断是重边还是反向边。 代码:#include #include

shinimashzi 243

大模型-CLIP 详细介绍

最先进的计算机视觉系统通常被训练来预测一组预定义的对象类别。这种受限的监督形式限制了它们的通用性和可用性,因为要指定任何其他视觉概念,就需要额外的标注数据。比如,它们可以识别“猫”、“狗”、“汽车”等。但是,这种做法有一个明显的局限性:如果你想让系统识别一个新的类别,比如说“独角兽”,你就必须提供大量带有“独角兽”标签的图片来训练系统。这不仅耗时费力,而且限制了系统的灵活性和广泛适用性。直接从原始文本中学习关于图像的信息是一种很有前途的替代方案,因为它利用了更广泛的监督来源。

晓的博客 9759

HDU 4612 Warm up 解题报告

比赛 题目 题意:给出n个点和m条边的图,存在重边,问加一条边以后,剩下的桥的数量最少为多少。 解法:先用tarjan缩点变成一棵树,然后求树的直径,显然,用一条边将直径的两个端点连起来可以让剩余的桥数量最少。要注意会有重边,在tarjan里面要判一下。 //time 1031MS //memory 31340K #pragma comment(linker, "/STACK:10240

Tri_integral的专栏 1973

SPSS中的数据分析—信度效度检验【1】

前一段时间跟大家分享了好几篇关于EXCEL方面的数据分析知识,不知道大家都掌握得怎么样了。今天咱们换个口味,给大家讲一下关于SPSS中的数据分析——信度效度检验。 现阶段正处在毕业季阶段,很多同学可能都正在忙着去弄自己的论文和答辩(不知道大家在翟天临上热搜这个事情上有没有做出过一定贡献),很多时候我们在写论文答辩甚至于其他课题研究的时候都会选择用问卷这种形式来收集数据。最后我们只需要针对问卷所取...

小白数据营的博客 6万+

嵌入式系统存储体系

主要分为三种:高速缓存(cache)、主存和外存。

weixin_43586667的博客 2271

hdu 4612 Warm up

http://acm.hdu.edu.cn/showproblem.php?pid=4612   Warm up Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 2012    Accepted Submission(s): 4

ddyyxx的程序员之路 1499

echarts实现3D地图——map3D

【代码】echarts实现3D地图——map3D。

xiaoququ的博客 7337

HDU4612 Warm up

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 11184 Accepted Submission(s): 2573 HDU4612 Warm up 文章目录Problem Description题意:题解:代码: Problem Description N planets are connected by M bidirectiona

qq_35975367的博客 355

块坐标下降法实战:如何用Python一步步优化无人机通信网络?

本文通过Python实战案例,详细介绍了块坐标下降法在优化无人机通信网络中的应用。文章以最大化网络吞吐量为目标,将复杂的非凸问题拆解为功率分配和轨迹规划两个子问题,并提供了完整的算法实现、代码示例及调参指南,为机器学习工程师解决类似优化问题提供了实用参考。

sat99的博客 982

Python爬虫实战:基于最新技术栈的政府招标采购数据抓取与分析

对于企业、研究人员和数据分析师来说,能够高效地获取这些数据意味着可以获得宝贵的商业洞察和市场先机。随着反爬技术的不断升级和网站结构的日益复杂,传统的爬虫方法已经难以满足需求。我们将采用Selenium、Playwright等现代浏览器自动化工具,结合Scrapy框架和异步请求库,构建一个能够应对各种反爬措施的强大爬虫系统。Playwright是微软开发的浏览器自动化工具,支持Chromium、WebKit和Firefox,比Selenium更快速、更稳定。

2201_76125261的博客 1316

【HDU4612 Warm up】

tarjan 树的直径 HDU4612 给定一个无向连通图,求增加一条边后,割边的最少可能的条数 先用tarjantarjantarjan缩点(边双连通分量),剩下的就是割边构成的树,我们在任意两点间加边,就等于在他们所在的边双连通分量加边 于是两个点在树上的链加上加的边构成的一个环,就减少了链长的割边 想要割边最少就是求树的直径 树的直径可以用新建图加两遍dfsdfsdfs 所以:tarjan...

cxr的博客 196

【数据集】1980-2020年(5年)土地利用分类数据-中国科学院

简介1980-2020年每五年土地利用数据-中国科学院

WW、forever的博客 3941

HDU 4612 - Warm up

Warm up Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 10532 Accepted Submission(s): 2432 Problem Description   N planets are connected by...

青烟绕指柔的博客 416

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

HDU 4612 Warm up

Warm up                                                    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)

ACM2272902662的专栏 931

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

hdu4612 Warm up

公开20190417远古博客,汗 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 题意: 给n个点m条无向边,保证整体是个连通图,问加一条边之后保留的桥数量最小值 思路: 无向图找桥,tarjan;之后缩点;再之后找到缩点之后由桥当作树边的树的直径,桥数-直径(最长路径长度)即为所求 坑: 1. 没有缩点,直接接拿桥做,这样生...

zlkqlyc的博客 156

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

HDU 4612 Warm up

Description   N planets are connected by M bidirectional channels that allow instant transportation. It’s always possible to travel between any two planets through these channels.   If we can isolat

u013570474的专栏 374

HDU-4612 Warm up

找出在无向图中加入一条边,使图中桥的数量最少是多少先缩点,找出各个强连通分量,找出的强连通分量个数-1就是桥的数量了缩点后重新建图,每个连通分量是一个点,由桥作为边连接这些点,这时候图就是一棵树了要想加入一条边,让桥最大数量减少,那么我们只需要找到树的直径,在直径两端加一条边,形成一个环详见代码#include&lt;iostream&gt; #include&lt;cstdio&gt; #inc...

wl16wzl的博客 348

Warm up HDU - 4612

题意: 给出一个n个点m条边的无向图,询问添加一条边后图中最少有多少个桥? 题解: 对无向图缩点,缩点后的DAG有多少条边即有多少个桥。 很明显添加一条边(u, v)后,DAG中的(u, v)路径上的桥都会失效。 那么我们直接找一条最长的路径即直径即可。 代码: /* * @Author : Nightmare */ #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned

qq_43544481的博客 158

hdu 4612 Warm up

将双连通分量浓缩成点,形成一颗树,找最长路 #include #include #include #include #include #define N 200010 #define M 1000010 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; bool iscut[2

moyan_min的专栏 1314

Hdu4612 Warm up

做这题是噩梦的一天….先用tarjan缩点求出各个强联通块并且找出桥数要求连一条边后得到的剩余最小的桥所以要找一条路能达到的最深的路径则ans = bridge - maxdeep先用spfa的dfs找出能达到的最大深度然后从最大深度开始搜索最大的深度最后相减就是答案 #include<stdio.h> #include<string.h> ...

weixin_30820151的博客 128

hdu 4612 Warm up 多校总结

题意: 求加入一条边(双向)后,图中桥最小的数量。 知识点: tarjan算法实现无向图缩点(变成树),求树的最大直径 答案 = 连通数 - 树的最大直径 - 1 PS: 输入存在重边,误删;当两个点由两条边相连时,这两个点连通(因为把重边删了,比赛的时候卡死在那里了) tarjan 算法标记‘边’(无向图) 求树的最大直径,使用一个定理,需要两次求最短路

海上机械师 1264

Warm up HDU - 4612 Tarjan,树的直径

N planets are connected by M bidirectional channels that allow instant transportation. It's always possible to travel between any two planets through these channels.    If we can isolate some planets

SUNSET 406

hdu 4612——Warm up

tarjan缩点+树的直径 https://www.byvoid.com/blog/scc-tarjan/    讲tarjian比较好 http://blog.csdn.net/u010638776/article/details/9472605   借鉴了这里 #include #include #include #include #pragma comment(linker, "/ST

1006
上一篇: POJ1985——Cow Marathon
下一篇: codeforces round # 273 div2 A, B, C题题解
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值