#include using namespace std; typedef long long LL; LL c[1001][1001]; LL dp[200][1001]; int z[300]; int w[300]; int d[300][300]; const LL MOD=1e9+7; void init_comb(int n){ n++;for(int i=0;i=b){ if(n&b)res=(res*a)%MOD; a=(a*a)%MOD;b<<=1; }return res; } inline void calc(int id,int n){ dp[id][0]=0; for(int m=1;m<=n;m++){ LL tmp=pow_mod(m,n); for(int i=1;i%d=%lld\n",n,m,tmp); } } int main() { fill((int*)d,(int*)d+300*300,0); int N,M; cin>>N>>M; for(int i=0;i>w[i]; d[i][i]=w[i]; } for(int i=0;i>from>>to; d[from-1][to-1]=min(w[from-1],w[to-1]); } int sz; map _z; /*init*/ { init_comb(1000); for(int i=0;i(%d)=%d:",i,w[i],j,d[i][j]); if(d[i][j]==w[j]){ res+=dp[_z[w[i]]][d[i][j]]; res%=MOD; // printf("%lld",dp[_z[w[i]]][d[i][j]]); } //cout<