#include<stdio.h> #include<string.h> #define ll long long struct node { ll wo;ll di; }map[205][205]; int n,m; int solve() { for(int i=1;i<=n;i++) { ll sset=0;ll tset=0; for(int j=1;j<=n;j++) { sset+=map[j][i].wo; tset+=map[i][j].di; } if(sset>tset) return 0; } return 1; } int main() { int CAS; scanf("%d",&CAS); for(int kcas=1;kcas<=CAS;kcas++) { for(int i=1;i<=202;i++) for(int j=1;j<=202;j++) { map[i][j].wo=0;map[i][j].di=0; } scanf("%d%d",&n,&m); int u,v;ll d,b; for(int i=1;i<=m;i++) { scanf("%d%d%lld%lld",&u,&v,&d,&b); map[u][v].wo=d; map[u][v].di=d+b; } if(solve()) printf("Case #%d: happy\n",kcas); else printf("Case #%d: unhappy\n",kcas); } return 0; } |
Double click to view unformatted code.