結果

問題 No.329 全射
ユーザー chocoruskchocorusk
提出日時 2019-01-26 19:34:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 99,844 KB
実行使用メモリ 19,520 KB
最終ジャッジ日時 2023-10-17 14:31:35
合計ジャッジ時間 3,993 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
19,316 KB
testcase_01 AC 11 ms
19,316 KB
testcase_02 AC 11 ms
19,316 KB
testcase_03 AC 11 ms
19,316 KB
testcase_04 AC 11 ms
19,316 KB
testcase_05 AC 11 ms
19,316 KB
testcase_06 AC 11 ms
19,316 KB
testcase_07 AC 11 ms
19,316 KB
testcase_08 AC 11 ms
19,316 KB
testcase_09 AC 12 ms
19,316 KB
testcase_10 AC 11 ms
19,316 KB
testcase_11 AC 11 ms
19,316 KB
testcase_12 AC 11 ms
19,316 KB
testcase_13 AC 129 ms
19,440 KB
testcase_14 AC 84 ms
19,360 KB
testcase_15 AC 85 ms
19,420 KB
testcase_16 AC 92 ms
19,520 KB
testcase_17 AC 105 ms
19,432 KB
testcase_18 AC 121 ms
19,520 KB
testcase_19 AC 136 ms
19,444 KB
testcase_20 AC 122 ms
19,440 KB
testcase_21 AC 104 ms
19,428 KB
testcase_22 AC 129 ms
19,392 KB
testcase_23 AC 21 ms
19,388 KB
testcase_24 AC 21 ms
19,388 KB
testcase_25 AC 29 ms
19,412 KB
testcase_26 AC 23 ms
19,368 KB
testcase_27 AC 13 ms
19,336 KB
testcase_28 AC 11 ms
19,320 KB
testcase_29 AC 13 ms
19,328 KB
testcase_30 AC 12 ms
19,328 KB
testcase_31 AC 11 ms
19,316 KB
testcase_32 AC 12 ms
19,332 KB
testcase_33 AC 12 ms
19,320 KB
testcase_34 AC 12 ms
19,320 KB
testcase_35 AC 12 ms
19,320 KB
testcase_36 AC 12 ms
19,320 KB
testcase_37 AC 12 ms
19,320 KB
testcase_38 AC 12 ms
19,320 KB
testcase_39 AC 12 ms
19,320 KB
testcase_40 AC 12 ms
19,320 KB
testcase_41 AC 12 ms
19,320 KB
testcase_42 AC 12 ms
19,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int n, m;
int w[200];
vector<int> g[200];
ll comb[1001][1001], pw[1001][1001];
void calc(){
	comb[0][0]=comb[1][0]=comb[1][1]=1;
	for(int i=2; i<=1000; i++){
		comb[i][0]=comb[i][i]=1;
		for(int j=1; j<i; j++){
			comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%MOD;
		}
	}
	for(ll i=0; i<=1000; i++){
		pw[i][0]=1;
		for(int j=1; j<=1000; j++){
			pw[i][j]=pw[i][j-1]*i%MOD;
		}
	}
}
bool used[200];
void dfs(int x, int w0){
	used[x]=1;
	for(auto y:g[x]){
		if(w[y]<w0) continue;
		if(used[y]) continue;
		dfs(y, w0);
	}
}
ll count(int w1, int w2){
	ll ret=0;
	for(int i=0; i<w2; i++){
		if(i&1){
			ret-=(comb[w2][i]*pw[w2-i][w1]%MOD);
			ret+=MOD;
		}else{
			ret+=(comb[w2][i]*pw[w2-i][w1]);
		}
		ret%=MOD;
	}
	return ret;
}
int main()
{
	cin>>n>>m;
	for(int i=0; i<n; i++) cin>>w[i];
	for(int i=0; i<m; i++){
		int x, y; cin>>x>>y; x--; y--;
		g[y].push_back(x);
	}
	calc();
	ll ans=0;
	for(int i=0; i<n; i++){
		fill(used, used+n, 0);
		dfs(i, w[i]);
		for(int j=0; j<n; j++){
			if(used[j]){
				ans+=count(w[j], w[i]);
				ans%=MOD;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
0