// aarifshuvo ``CSEJU #include <bits/stdc++.h> #define ll long long #define SZ(x) ((int)(x).size()) #define scl(x) scanf("%lld", &x) #define scll(x,y) scanf("%lld %lld", &x, &y) #define ALL(x) (x).begin(),(x).end() #define REP(i,n) for(int i=0;i<n;i++) #define REV(i,n) for(int i=n-1;i>=0;i--) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define pri(a) cout<<a<<endl #define prii(a,b) cout<<a<<" "<<b<<endl using namespace std; int main() { ll n,m; ll arr[10],a[22],b[22],c[22]; while(scll(n,m)==2 && n+m) { REP(i,m) scll(a[i],b[i]), scl(c[i]); REP(i,n) arr[i]=i; ll ans = 0,fl=1; do { REP(i,m) { ll df = abs(arr[a[i]]-arr[b[i]]); if(c[i]>0 and df<=c[i]) fl=1; else if(c[i]<0 and df>=(-c[i])) fl=1; else { fl=0; break; } } if(fl) ans++; }while(next_permutation(arr,arr+n)); printf("%lld\n", ans); } return 0; }
~Be glad of life because it gives you the chance to love and to work and to play and to look at the stars.~
Thursday, June 1, 2017
UVa 11742 - Social Constraints
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment