当前位置:网站首页>DFS and BFS concepts of trees and graphs
DFS and BFS concepts of trees and graphs
2022-07-05 03:56:00 【Cherish forever】
1. Depth first traversal enters the recursive call itself every time you search
2. Width first traversal is not recursive, that is, search the next node that the current node can reach until the node is searched
Use Adjacency list
Traverse : Each point will be traversed only once
1. Depth-first traversal .
Search as deep as possible , Go back when you hit the bottom , Until you search all the points .
2. Breadth first traversal .
Search widely from the root node , Search all the points on the first floor every time .
void add(int a,int b) {
e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
int dfs(int x) {
st[x]=true;
int size=0,sum=1;
for(int i=h[x]; i!=-1; i=ne[i]) {
int j=e[i];
if(st[j]) continue;
int s=dfs(j);
size=max(size,s);
sum+=s;
}
size=max(size,n-sum);
ans=min(size,ans);
return sum;
}
边栏推荐
- v-if VS v-show 2.0
- IronXL for . NET 2022.6
- 已解决(sqlalchemy+pandas.read_sql)AttributeError: ‘Engine‘ object has no attribute ‘execution_options‘
- IronXL for .NET 2022.6
- Deflocculant aminoiodotide eye drops
- [software reverse analysis tool] disassembly and decompilation tool
- 线程基础知识
- PlasticSCM 企业版Crack
- ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 1)
- [software reverse - basic knowledge] analysis method, assembly instruction architecture
猜你喜欢
[learning notes] month end operation -gr/ir reorganization
Some enterprise interview questions of unity interview
Clickhouse同步mysql(基于物化引擎)
On the day 25K joined Tencent, I cried
Special Edition: spreadjs v15.1 vs spreadjs v15.0
[wp]bmzclub writeup of several questions
Subversive cognition: what does SRE do?
我就一写代码的,王总整天和我谈格局...
【无标题】
[brush questions] BFS topic selection
随机推荐
v-if VS v-show 2.0
@Transactional 注解导致跨库查询失效的问题
[punch in questions] integrated daily 5-question sharing (phase III)
MindFusion.Virtual Keyboard for WPF
Difference between MotionEvent. getRawX and MotionEvent. getX
Basic knowledge of tuples
[summary of two registration methods]
Technology sharing swift defense programming
Yuancosmic ecological panorama [2022 latest]
Enterprise level: spire Office for . NET:Platinum|7.7. x
Plasticscm enterprise crack
Flex flexible layout
grandMA2 onPC 3.1.2.5的DMX参数摸索
程序员的视力怎么样? | 每日趣闻
UI自動化測試從此告別手動下載瀏覽器驅動
[untitled]
函数基础学习02
IronXL for . NET 2022.6
ActiveReportsJS 3.1 VS ActiveReportsJS 3.0
laravel8 导出Excle文件