七下编程笔记

2023-2-19

1、并查集

2023-2-24

1、位运算:

	if(x&(x-1))//求出x中的一
	x>>=1//除2	
	x&(-x)//得到一个低位1的二进制数
	log2(k)//的返回值为double类型

2、图:
题:

C. Bridge
内存限制:256 MiB
时间限制:1000 ms
标准输入输出
题目类型:传统
评测方式:文本比较
题目描述
给你一个个点条边无重边无自环的无向图。

求有几个桥边。删除后使得图不连通的边称为桥边。

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 leq i leq M) connects Vertex a_i and Vertex b_i.

An edge whose removal disconnects the graph is called a bridge.
Find the number of the edges that are bridges among the M edges.

输入格式
第一行两个正整数,之后行每行两个数描述无向边。

Input is given from Standard Input in the following format:

N M  
a_1 b_1  
a_2 b_2
:  
a_M b_M
输出格式
一个正整数代表图里有几个桥。

Print the number of the edges that are bridges among the M edges.

样例
样例输入1
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7
样例输入2
3 3
1 2
1 3
2 3
样例输入3
6 5
1 2
2 3
3 4
4 5
5 6
样例输出1
4
样例输出2
0
样例输出3
5
数据范围与提示
2 ≤ N ≤ 50 N − 1 ≤ M ≤ min(N(N − 1) / 2, 50)

代码

#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int e[55][55];
bool f[55];
pair<int, int> edge[1500];
int x,y;
void dfs(int x){
	f[x]=1;
	for(int j=1;j<=n;j++){
		if(e[x][j]&&!f[j]){
			dfs(j);
		}
	}
}
bool ch(){
	memset(f,0,sizeof(f));
	dfs(1);
	for(int i=1;i<=n;i++){
		if(!f[i]){
			return 1;
		}
	}
	return 0;
}
int u,v;
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		
		cin>>u>>v;
		e[u][v]=e[v][u]=1;
		edge[i]=make_pair(u,v);
	}
	for(int i=1;i<=m;i++){
		x=edge[i].first;
		y=edge[i].second;
		e[x][y]=e[y][x]=0;
		ans+=ch();
		e[x][y]=e[y][x]=1;
	}
	cout<<ans;
}

难受😭

考试调皮,被踢出编程舍了

如有错误,尽情在评论区指出,谢谢!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值