如果你除了Test #5都TLE Like This,请检查你的add_edge()函数。
注意建反向边的时候价值要改为负的。
Incorrect Code:
void add_edge(int x, int y, int z, int cost) {
e[tot]={y, head[x], z, cost}, head[x]=tot++;
e[tot]={x, head[y], 0, cost}, head[y]=tot++;
}
Correct Code:
void add_edge(int x, int y, int z, int cost) {
e[tot]={y, head[x], z, cost}, head[x]=tot++;
e[tot]={x, head[y], 0, -cost}, head[y]=tot++;
}