#include "bits/stdc++.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) using namespace std; using ld = long double; template using Table = vector>; const ld eps=1e-9; #define WHATS(var)cout<<__LINE__<<' '<<#var<<"="< ostream& operator <<(ostream &os, const pair v){ os << "( " << v.first << ", " << v.second << ")"; return os; } template ostream& operator <<(ostream &os, const vector &v){ for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os; } template ostream& operator <<(ostream &os, const vector> &v){ for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os; } template ostream& operator <<(ostream &os, const vector> &v){ for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os; } template ostream& operator <<(ostream &os, const set &v){ int i=0; for(auto it:v){ if(i > 0){os << ' ';} os << it; i++; } return os; } /* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 12 1 11 13 3 10 14 5 9 15 7 8 16 2 14 17 4 13 18 6 12 1-12 11 1 10 12 3 9 13 5 8 13 6 7 14 2 12 15 4 11 */ const int MAX_X=10; using ll=long long ; const int mod = 1000000007; struct Mod { public: int num; Mod() : Mod(0) { ; } Mod(long long int n) : num((n % mod + mod) % mod) { static_assert(mod(n)) { ; } operator int() { return num; } }; Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); } Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; } Mod operator+(const Mod a, const long long int b) { return b + a; } Mod operator++(Mod &a) { return a + Mod(1); } Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); } Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; } Mod operator--(Mod &a) { return a - Mod(1); } Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); } Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; } Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; } Mod operator*(const Mod a, const int b) { return Mod(b)*a; } Mod operator+=(Mod &a, const Mod b) { return a = a + b; } Mod operator+=(long long int &a, const Mod b) { return a = a + b; } Mod operator-=(Mod &a, const Mod b) { return a = a - b; } Mod operator-=(long long int &a, const Mod b) { return a = a - b; } Mod operator*=(Mod &a, const Mod b) { return a = a * b; } Mod operator*=(long long int &a, const Mod b) { return a = a * b; } Mod operator*=(Mod& a, const long long int &b) { return a = a * b; } Mod operator^(const Mod a, const int n) { if (n == 0) return Mod(1); Mod res = (a * a) ^ (n / 2); if (n % 2) res = res * a; return res; } Mod mod_pow(const Mod a, const int n) { if (n == 0) return Mod(1); Mod res = mod_pow((a * a), (n / 2)); if (n % 2) res = res * a; return res; } Mod inv(const Mod a) { return a ^ (mod - 2); } Mod operator/(const Mod a, const Mod b) { assert(b.num != 0); return a * inv(b); } Mod operator/(const long long int a, const Mod b) { return Mod(a) / b; } Mod operator/=(Mod &a, const Mod b) { return a = a / b; } #define MAX_MOD_N 1024000 Mod fact[MAX_MOD_N], factinv[MAX_MOD_N]; void init(const int amax = MAX_MOD_N) { fact[0] = Mod(1); factinv[0] = 1; for (int i = 0; i < amax - 1; ++i) { fact[i + 1] = fact[i] * Mod(i + 1); factinv[i + 1] = factinv[i] / Mod(i + 1); } } Mod comb(const int a, const int b) { return fact[a] * factinv[b] * factinv[a - b]; } int main() { init(); ios::sync_with_stdio(false); int N,M;cin>>N>>M; vectorszs(N); for(int i=0;i>szs[i]; vector>graph(N); for(int i=0;i>u>>v;u--;v--; graph[u].push_back(v); } vector>pluss(MAX_X+1,vector(MAX_X+1)); for(int start=0;startmaxs(N,-1); maxs[start]=szs[start]; priority_queue>que; que.emplace(szs[start],start); maxs[start]=szs[start]; while(!que.empty()){ auto p=que.top(); int now=p.second; que.pop(); if(p.first!=maxs[now])continue; for(auto e:graph[now]){ int n_sz=min(maxs[now],szs[e]); if(maxs[e]=szs[i]){ pluss[szs[start]][szs[i]]++; } } } //WHATS(pluss) vector>dp(MAX_X+1,vector(MAX_X+1)); dp[1][1]=Mod(1); for(int y=2;y<=MAX_X;++y){ for(int x=1;x<=y;++x){ dp[y][x]=dp[y-1][x-1]+dp[y-1][x]*x; } } //WHATS(dp) Mod answer=0; for(int i=0;i<=MAX_X;++i){ for(int j=0;j<=MAX_X;++j){ Mod aanswer=dp[i][j]*Mod(pluss[i][j])*fact[j]; answer+=aanswer; } } cout<