想过无源汇的网络流,还是比较麻烦的,然后没往下想。。。
设s点集有一些点,
多加一个点一定是y增加比较快_(:зゝ∠)_然后设s点集只有一个点
#include <cstdio> #include <map> #include <set> #include <algorithm> using namespace std; #define N 205 struct node{ int to, d, b, nex; }edge[5005], edge2[5005]; int head[N], edgenum; void add(int u, int v, int d, int b){ node E = {v, d, b, head[u]}; edge[edgenum] = E; head[u] = edgenum++; } int head2[N], edgenum2; void add2(int u, int v, int d, int b){ node E = {v, d, b, head2[u]}; edge2[edgenum2] = E; head2[u] = edgenum2++; } void init(){memset(head, -1, sizeof head), edgenum = 0;memset(head2, -1, sizeof head2), edgenum2= 0 ;} int n, m; bool work(int x){ int hehe = 0, gg = 0; for(int i = head[x]; ~i; i = edge[i].nex){ hehe += edge[i].d; } for(int i = head2[x]; ~i; i = edge2[i].nex){ gg += edge2[i].d + edge2[i].b; } return hehe>gg; } int main() { int T,u,v,a,b, Cas = 1; scanf("%d", &T); while(T-- > 0) { scanf("%d %d",&n,&m); init(); while(m--) { scanf("%d %d %d %d",&u,&v,&a,&b); add(u, v, a, b); add2(v, u, a, b); } printf("Case #%d: ",Cas++); bool yes = true; for(int i = 1; yes && i <= n; i++) { if(work(i)) yes = false; } yes ? puts("happy"):puts("unhappy"); } return 0; } /* 5 5 1 1 1 10 8 1 1 2 2 1 2 3 1 1 3 2 2 2 3 2 1 3 2 3 2 2 3 3 3 */
HDU 4940 Destroy Transportation system 规律题,布布扣,bubuko.com
HDU 4940 Destroy Transportation system 规律题
原文:http://blog.csdn.net/qq574857122/article/details/38518189