这道题目当时做的时候想的是,如果找到一个点他的d值之和大于 d+b值之和,就可以。竟然就这么过了啊。不过题解上还有一种做法,好像有点难。以后在补一补那种做法吧。


2 3 3 1 2 2 2 2 3 2 2 3 1 2 2 3 3 1 2 10 2 2 3 2 2 3 1 2 2
Case #1: happy Case #2: unhappyHintIn first sample, for any set S, X=2, Y=4. In second sample. S= {1}, T= {2, 3}, X=10, Y=4.
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define M 1000100
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x)
const int maxn = 2010;
using namespace std;
struct node
{
int x, y;
} f[maxn];
int main()
{
int T;
cin >>T;
int Case = 1;
while(T--)
{
int n, m;
cin >>n>>m;
int x, y;
int d, b;
for(int i = 0; i <= n; i++) f[i].x = f[i].y = 0;
for(int i = 0; i < m; i++)
{
scanf("%d %d %d %d",&x, &y, &d, &b);
f[x].y += d;
f[y].x += (d+b);
}
int flag = 0;
for(int i = 1; i <= n; i++)
{
if(f[i].x < f[i].y)
{
flag = 1;
break;
}
}
cout<<"Case #"<<Case++<<": ";
if(flag) cout<<"unhappy"<<endl;
else cout<<"happy"<<endl;
}
return 0;
}HDU 4940 Destroy Transportation system(图论),布布扣,bubuko.com
HDU 4940 Destroy Transportation system(图论)
原文:http://blog.csdn.net/xu12110501127/article/details/38553649