結果
| 問題 |
No.329 全射
|
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2015-12-22 22:19:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,079 bytes |
| コンパイル時間 | 1,376 ms |
| コンパイル使用メモリ | 171,212 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-18 18:48:58 |
| 合計ジャッジ時間 | 21,071 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 TLE * 3 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
ll inv(ll x){
ll t = MOD-2;
ll r = 1;
while(t){
if(t&1)r=r*x%MOD;
x=x*x%MOD;
t>>=1;
}
return r;
}
ll mypow(ll a,ll x){
if(x==0)return 1;
ll p = mypow(a,x/2);
p = p*p%MOD;
if(x&1) p = p*a%MOD;
return p;
}
ll fact[1010];
ll comb(ll a,ll b){
if(a-b<0)return 0;
return fact[a]*inv(fact[a-b])%MOD*inv(fact[b])%MOD;
}
ll zmemo[1010][1010];
ll zensha(ll n,ll k){
if(zmemo[n][k])return zmemo[n][k];
ll ret = 0;
REPR(i,k+1){
ll tmp = 1;
if((k-i)%2==1)tmp = MOD-1;
tmp = tmp*comb(k,i)%MOD;
tmp = tmp*mypow(i,n)%MOD;
ret = (ret+tmp)%MOD;
}
return zmemo[n][k]=ret;
}
int main(){
fact[0] = 1;
REPR(i,1010) fact[i] = fact[i-1]*i%MOD;
ll n,m;
cin>>n>>m;
vl w(n);
REP(i,n) cin>>w[i];
vl G[n];
REP(i,m){
ll x,y;
cin>>x>>y;
--x;--y;
if(x==y)continue;
G[x].push_back(y);
}
ll result = 0;
REP(src,n){
vl flow(n,0);
flow[src] = w[src];
priority_queue<pll> Q;
Q.push(make_pair(flow[src],src));
vector<bool> used(n,false);
while(!Q.empty()){
pll P = Q.top(); Q.pop();
ll f = P.first;
ll u = P.second;
if(used[u])continue;
used[u] = true;
REP(ed,G[u].size()){
ll v = G[u][ed];
if(flow[v]>=min(f,w[v]))continue;
flow[v]=min(f,w[v]);
Q.push(make_pair(flow[v],v));
}
}
REP(to,n){
if(flow[to]==w[to]){
result += zensha(w[src],w[to]);
result %= MOD;
}
}
}
cout << result << endl;
return 0;
}
rickytheta