版本比较
「学习笔记」图论Ⅱ
正文
增加 9 行删除 9 行
97 行未改动9899100101102102103104105106328 行未改动全部展开4354364374384394394404414424434 行未改动4484494504514524524534544554563 行未改动460461462463464464465466467468126 行未改动全部展开59559659759859959960060160260344 行未改动64864965065165265265365465565634 行未改动69169269369469569569669769869957 行未改动757758759760761761762763764765765766767768769148 行未改动全部展开97 行未改动 } dijstra(); for(int i=1;i<=n;i++)cout<<dis[i]<<' '; return 0;} }```#### 堆优化
```cpp328 行未改动全部展开算法实现
- 建树-$buildtree$> 将 `a[n]` 不断二分转化为线段树数组 `tree[4*n]`。> >> ```cpp> void buildtree(int lowbit,int l,int r){> if(l==r){tree[lowbit]=a[l]return;}> int mid=(l+r)>>1;4 行未改动> ```
- 更新-$lazy\ tag$> 找到所对应区间,放下懒标记,返回时层层更改,查询时同样更改。> >> - $Lazy$_$tag\ Code$> ```cpp> void push_up(int lowbit){> tree[lowbit]=max(tree[lowbit<<1],tree[lowbit<<1|1]);3 行未改动> tree[lowbit<<1]+=lazy_tag[lowbit],tree[lowbit<<1|1]+=lazy_tag[lowbit];> lazy_tag[lowbit]=0;> }> ```> >> - $Add\ Code$> ```cpp> void add(int lowbit,int l,int r,int b,int e,int tmp){> if(b<=l&&r<=e){tree[lowbit]+=tmp;lazy_tag[lowbit]+=tmp;return;}126 行未改动全部展开树上最长的路径。
- 求法
>- [] 树上 dp >- [] 树上 dp>>~~不会QWQ~~>>- [] $2\cdot$bfs44 行未改动 qwq.push(to[i]); vis[to[i]]=1; } } } } }}inline int read(){ int x=0,f;char ch=0;34 行未改动
- 预处理
> ```cpp> >> for(int j=1;j<=(int)(log(n)/log(2));j++)> for (int i=1;i<=n-(1<<j)+1;i++)> f[i][j]=min(f[i][j-1],f[i+(1<<(j-1))][j-1]);> ```57 行未改动
- solve(洛谷P8655)
> - 拓扑排序> >> ```cpp> #include<bits/stdc++.h>> using namespace std;> const int N=1e5+1; > const int N=1e5+1;> int n;> int in[N];> vector<int>e[N];> bool vis[N];//标记入度是否为1,即该点是否在环上148 行未改动全部展开