Bridge - 判断图是否连通 - 图的遍历 or 并查集搜索 or 强连通算法

问题

原题戳这 <<
Time limit : 2sec / Memory limit : 256MB
Score : 300 points

Problem Statement

You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.
The i-th edge (1≤i≤M) connects Vertex ai and Vertex bi.
An edge whose removal disconnects the graph is called a bridge.
Find the number of the edges that are bridges among the M edges.

Notes

A self-loop is an edge i such that ai=bi (1≤i≤M).
Double edges are a pair of edges i,j such that ai=aj and bi=bj (1≤i

Constraints

2≤N≤50
N−1≤M≤min(N(N−1)⁄2,50)
1≤ai< bi≤N
The given graph does not contain self-loops and double edges.
The given graph is connected.

Sample Input 1

7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7

Sample Output 1

4

题解

题意,给你n个点m条边,要求去掉一个边,无向图是否连通。

代码1

这个是我无数次RE后,无数次修改,发现用queue判断是否是连通比dfs判断快?反正以后就用queue了。
时间复杂度:O(m^2)

#include<cstdio>
#include<queue>
using namespace std;

bool ma[55][55];
int n,m;
bool solve()
{
  
  //判断图是否连通
    bool vis[55]={
  
  0};
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值