版本比较
Day 2 2026/08/04
正文
增加 68 行删除 3 行
136 行未改动全部展开137138139140141141142143144145145146147147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212136 行未改动全部展开 - 广度优先遍历
**树的扩展练习题**
B3861 [子树和](https://www.luogu.com.cn/problem/B3861) B3861 子树和
T346655 [判断平衡二叉树](https://www.luogu.com.cn/problem/T346655)
P17013[GESP202606 六级\ 满二叉树](https://www.luogu.com.cn/problem/P17013) P17013[[GESP202606 六级\] 满二叉树](https://www.luogu.com.cn/problem/P17013)
P1612 [yLOI2018\ 树上的链](https://www.luogu.com.cn/problem/P1612) P1612 [[yLOI2018\] 树上的链](https://www.luogu.com.cn/problem/P1612)
7. 图
**图的概念**
- 有向图与无向图
- 无向图的连通图与非连通图
- 有向图的强连通与非强连通
- 简单图与多重图
- 无权图与带权图(点权、边权)
**图的存储**
- 邻接矩阵 `G[i][j]` 表示顶点 i 到 j 的边的状态
- 边集数组 `struct EDGE {int x,y,z;} edges[MAXN]` 存储第 i 条边的起点终点和边权(普及组没有相关算法)提高组 SPFA 与 kruskal 算法。
- 邻接表
- `vector<int> G[MAXN]`
- 链式前向星
```c++ const int N = 1e5 + 5,M = 4e5 + 5; int head[N],cnt; // head 是多头节点,cnt 表示已经分配了多少个节点 struct EDGE{ int nxt,y,z; // 表示下一条边的编号,当前边的终点,当前边的边权 }edges[M<<1]; // 无向图开 2 倍边,有向图 1 倍边,分层图 k+1 倍边 // 多头链表的头插法插入边 void add(int x,int y,int z){ // 向图中添加一条 起点为 x 终点为 y 边权为 z 的边 ++cnt; // 分配一个新的节点(边) edges[cnt].nxt = head[x]; // edges[cnt] = {head[x],y,z}; edges[cnt].y = y; // head[x] = cnt edges[cnt].z = z; head[x] = cnt; } // 遍历图中的所以边 for(int x=1;x<=n;x++) // 遍历图中的所有顶点 for(int i=head[x]; i!=0; i=edges[i].nxt){ int y= edge[i].y, d=edge[i].z; ... } ``` **图的遍历** - 深度优先遍历 - 广度优先遍历 **图的习题** P14077 [[GESP202509 七级\] 连通图](https://www.luogu.com.cn/problem/P14077) P3110 [USACO14DEC] Piggy Back S T402101 [0-1 最短路](https://www.luogu.com.cn/problem/T402101)