版本比较
ARC117 题解
正文
增加 2 行删除 2 行
82 行未改动8384858687888788899091925 行未改动82 行未改动直接建图跑 SPFA 是 $\mathcal{O}(n^2\log n)$,不能通过。但是图比较特殊,可以考虑”手动“找负环。
先把图在纸上画出来,容易发现负环总共有两种情况:
1. (不经过 $0\rightarrow 2n$ 的边) 2. (经过 $0\rightarrow 2n$ 的边) 1. (不经过 $0\rightarrow 2n$ 的边)2. (经过 $0\rightarrow 2n$ 的边)
*图和细节明天补* *明天的明天再补*
然后考虑 dp。$dp_{i,0/1}$ 分别表示目前在 $i+n$ 和 $i$ 时走过的最短路径长度。然后做一遍 $\mathcal{O}(n)$ 的 dp 即可。5 行未改动