不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解 不是讨论区题解
考虑拆边,变为 tot 与 tot+M,fr 连向 tot+M,tot 连向 to。
tot+M 流量为 1 连向 T,S 流量为 1 连向 tot,以最大流约束遍历。
tot+M 流量 inf 连向 tot,表示重开经过该边。
add2(s,1,inf,0);
for(int i=1,x,y,z;i<=n;i++){
scanf("%d",&x);
for(int j=1;j<=x;j++){
scanf("%d%d",&y,&z);
++tot;
add2(i,n+5000+tot,inf,z);
add2(n+5000+tot,t,1,0);
add2(n+5000+tot,n+tot,inf,0);
add2(s,n+tot,1,0);
add2(n+tot,y,inf,0);
}
}