正文
增加 1 行删除 1 行
228 行未改动全部展开22923023123223323423523623778 行未改动228 行未改动全部展开- `to[t]`:对每个 $t$ ,按 $dist[y][t]$ 从小到大给出所有 $y$ 的顺序。当我们枚举 $t$ 并按 `to[t]` 的顺序扫描 $y$ 时,定义阈值 $\text{need}(s,t,y)=dist[s][t]-dist[y][t]$,那么对该 $(s,t,y)$,**恰当且仅当** $f[s][x] < \text{need}(s,t,y)$ ,这些 $x$ 才有正贡献,且每个可行 $x$ 的增量是 $c[s][t]\cdot\bigl((dist[s][t]-dist[y][t]) - dist[s][x]\bigr)$由于我们在 `to[t]` 上让 $dist[y][t]$ 递增,$\text{need}$ **单调递减**。用一个指针 `pos` 在 `from[s]` 的序列上维护“可行前缀长度”。随着 $\text{need}$ 变小,`pos` 单调左移,对每个$t$ 总共 $O(n)$ 。考虑差分,把对“前缀 $[1..pos]$ ”的操作集中到两张表:78 行未改动228 行未改动全部展开22923023123223323423523623778 行未改动228 行未改动全部展开- `to[t]`:对每个 $t$ ,按 $dist[y][t]$ 从小到大给出所有 $y$ 的顺序。当我们枚举 $t$ 并按 `to[t]` 的顺序扫描 $y$ 时,定义阈值 $\text{need}(s,t,y)=dist[s][t]-dist[y][t]$,那么对该 $(s,t,y)$,**恰当且仅当** $f[s][x] < \text{need}(s,t,y)$ ,这些 $x$ 才有正贡献,且每个可行 $x$ 的增量是 $c[s][t]\cdot\bigl((dist[s][t]-dist[y][t]) - dist[s][x]\bigr)$由于我们在 `to[t]` 上让 $dist[y][t]$ 递增,$\text{need}$ **单调递减**。用一个指针 `pos` 在 `from[s]` 的序列上维护“可行前缀长度”。随着 $\text{need}$ 变小,`pos` 单调左移,对每个$t$ 总共 $O(n)$ 。考虑差分,把对“前缀 $[1..pos]$ ”的操作集中到两张表:78 行未改动