#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N,M; int W[300]; int I[40404],J[40404]; ll mo=1000000007; int mat[300][300]; static const int N_=1020; static ll C_[N_][N_]; ll fact[1010][1010]; ll dp[1010][1010]; inline int mulmod(int a,int b,int mo) { int d,r; if(a==0 || b==0) return 0; if(a==1 || b==1) return max(a,b); __asm__("mull %4;" "divl %2" : "=d" (r), "=a" (d) : "r" (mo), "a" (a), "d" (b)); return r; } void solve() { int i,j,k,l,r,x,y,z; string s; FOR(i,N_) C_[i][0]=C_[i][i]=1; for(i=1;i>N>>M; FOR(i,N) { cin>>W[i], mat[i][i]=W[i]; z=W[i]; for(x=1;x<=z;x++) { dp[z][x]=fact[x][z]; for(y=1;y>I[i]>>J[i], I[i]--, J[i]--; mat[I[i]][J[i]]=min(W[I[i]],W[J[i]]); } FOR(z,N) FOR(x,N) FOR(y,N) mat[x][y] = max(mat[x][y], min(mat[x][z],mat[z][y])); ll ret=0; FOR(x,N) FOR(y,N) if(mat[x][y]>=W[y] && W[x]>=W[y]) ret +=dp[W[x]][W[y]]; cout<