早就 A 了,偶然看到我的一个 219892 KiB 的代码,于是写下题解 .
https://www.luogu.com.cn/problem/P5025,BZOJ 过了,luogu 没过
题解:
先线段树优化建图,跑 tarjan 缩点,跑的时候记录强连通分量能到达的左右端点,然后再 dfs 一遍,用 \(u\) 能到的所有节点 \(v\) 来更新它能到的左右端点 .
然后就能求权值和了,答案显然能求了 .
时间复杂度 \(O(n\log n)\) .
丑陋の代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include