QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#346526#8325. 重塑时光Williamxzh40 314ms6148kbC++144.8kb2024-03-08 17:11:042024-03-08 17:11:04

Judging History

你现在查看的是最新测评结果

  • [2024-03-08 17:11:04]
  • 评测
  • 测评结果:40
  • 用时:314ms
  • 内存:6148kb
  • [2024-03-08 17:11:04]
  • 提交

answer

#include <bits/stdc++.h>
#define il inline
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
il ll qp(ll a,ll b){
    ll ans=1ll;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        a=(a*a)%mod,b>>=1;
    }
    return ans;
}
il void add(ll &x,ll y){x=(x+y>=mod?x+y-mod:x+y);}
const int N=16;
int n,m,k,e[N][N],a[N*2],b[N],vis[N*2],p[N];ll fac[N*2],inv[N*2],f[1<<N],ans;
il void init(){
    fac[0]=1ll;for(int i=1;i<=n*2;++i) fac[i]=(fac[i-1]*1ll*i)%mod;
    inv[n*2]=qp(fac[n*2],mod-2ll);for(int i=n*2-1;i>=0;--i) inv[i]=(inv[i+1]*(i+1ll))%mod;
}
il ll C(int n,int m){return (n<0 || m<0 || n<m)?0ll:(fac[n]*inv[m]%mod*inv[n-m])%mod;}
int g[N][N],in[N];pii d[N];int cnt,id[N*2];
il void get(){
    int x,y,z,cc;queue<int> q;
    for(int i=1;i<=n;++i) p[i]=i;
    do{
        cc=1;
        for(int i=1;i<=n;++i) a[i]=p[i];
        for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) g[i][j]=0;
        for(int i=1;i<=n+k;++i) vis[i]=id[i]=0;
        for(int i=1;i<=k;++i){
            x=b[i];
            for(int j=n+i;j>x;--j) a[j]=a[j-1];
            a[x]=0;
        }
        cnt=0;
        for(int i=1;i<=n+k;++i){
            if(!a[i]) continue;
            x=i;while(x<n+k && a[x+1]) ++x;
            d[++cnt]={i,x};
            for(int j=i;j<=x;++j) id[a[j]]=cnt;
            i=x;
        }
        for(int i=1;i<=cnt;++i){
            x=d[i].fi,y=d[i].se;
            for(int j=x;j<=y;++j) for(int l=j+1;l<=y;++l) if(e[a[l]][a[j]]) {cc=0;break;}
            if(!cc) break;
        }
        if(!cc) continue;
        for(int i=1;i<=n;++i)
            for(int j=1;j<=n;++j)
                if(e[i][j] && id[i]!=id[j]) g[id[i]][id[j]]=1;
        for(int i=1;i<=cnt;++i) in[i]=0;
        for(int i=1;i<=cnt;++i)
            for(int j=1;j<=cnt;++j)
                if(g[i][j] && i!=j) ++in[j];
        for(int i=1;i<=cnt;++i) vis[i]=0;
        for(int i=1;i<=cnt;++i) if(!in[i]) q.push(i),vis[i]=1;
        while(q.size()){
            x=q.front();q.pop();
            for(int y=1;y<=cnt;++y){
                if(!g[x][y]) continue;
                if(vis[y]) continue;
                if(!(--in[y])) vis[y]=1,q.push(y);
            }
        }
        for(int i=1;i<=cnt;++i) if(in[i]) cc=0;
        if(cc) ++ans;
    }while(next_permutation(p+1,p+1+n));
}
void dfs(int x){
    if(x>k){get();return ;}
    for(int i=1;i<=n+x;++i) b[x]=i,dfs(x+1),b[x]=0;
}
il void ad(ll &x,ll y){x=(x+y>=mod?x+y-mod:x+y);}
ll h[N][N][N*2][N*2];
int x,y;ll u,v,w;
int main(){
    //freopen("timeline.in","r",stdin);
    //freopen("timeline.out","w",stdout);
    scanf("%d%d%d",&n,&m,&k);init();
    for(int i=1;i<=m;++i) scanf("%d%d",&x,&y),e[x][y]=1;
    if(!m){printf("1");exit(0);}
    if(!k){
        f[0]=1ll;int S=(1<<n);
        for(int i=0;i<S;++i){
            for(int j=0;j<n;++j){
                if((i>>j)&1) continue;
                x=1;
                for(int k=0;k<n;++k){
                    if(!((i>>k)&1)) continue;
                    if(e[j+1][k+1]) {x=0;break;}
                }
                if(x) add(f[i|(1<<j)],f[i]);
            }
        }
        printf("%lld",(f[S-1]*inv[n])%mod);
        exit(0);
    }
    if(n<=5){
        dfs(1);
        u=1ll;for(int i=1;i<=k;++i) u=(u*(n+i))%mod;
        printf("%lld",(ans*inv[n]%mod*qp(u,mod-2ll))%mod);
        exit(0);
    }
    x=0;for(int i=2;i<=n;++i) x+=e[1][i];
    if(m==n-1 && x==n-1){
        ans=(C(n+k-1,n-1)*fac[n-1]%mod*fac[k])%mod;
        if(k) ans=(ans+(n+k-1)*C(n+k-2,n-1)*fac[n-1]%mod*fac[k])%mod;
        u=1ll;for(int i=1;i<=k;++i) u=(u*(n+i))%mod;
        printf("%lld",(ans*inv[n]%mod*qp(u,mod-2ll))%mod);
        exit(0);
    }
    if(m==n*(n-1)/2){
        h[0][1][0][0]=1ll;
        for(int i=0;i<k;++i){
            for(int j=1;j<=i+1;++j){
                for(int u=0;u<=i;++u){
                    for(int v=0;v<=n+k;++v){
                        //h[i+1][j+1][u]=(h[i+1][j+1][u]+h[i][j][u]*(n-j))%mod;
                       //h[i+1][j][u+1]=(h[i+1][j][u+1]+h[i][j][u]*(u+2ll))%mod;
                       // h[i+1][j][u]=(h[i+1][j][u]+h[i][j][u]*)
                        add(h[i+1][j+1][u][v+2],(h[i][j][u][v]*(n-j))%mod);
                        add(h[i+1][j][u+1][v],h[i][j][u][v]*(u+2ll)%mod);
                        add(h[i+1][j][u][v+1],h[i][j][u][v]*v%mod);
                    }
                }
            }
        }
        for(int i=1;i<=k+1;++i){
            ll x=0ll;
            for(int j=0;j<=n+k;++j)
                for(int u=0;u<=n+k;++u)
                    add(x,h[k][i][j][u]);
            ans=(ans+x*fac[i])%mod;
        }
        u=1ll;for(int i=1;i<=k;++i) u=(u*(n+i))%mod;
        printf("%lld",(ans*inv[n]%mod*qp(u,mod-2ll))%mod);
        exit(0);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 1ms
memory: 6148kb

input:

3 2 0
1 2
1 3

output:

333333336

result:

ok single line: '333333336'

Test #2:

score: 5
Accepted
time: 314ms
memory: 3808kb

input:

5 7 5
1 4
2 3
1 2
4 5
2 5
2 4
1 5

output:

895039689

result:

ok single line: '895039689'

Test #3:

score: 5
Accepted
time: 0ms
memory: 5884kb

input:

13 12 13
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13

output:

76923078

result:

ok single line: '76923078'

Test #4:

score: 5
Accepted
time: 0ms
memory: 5884kb

input:

14 13 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14

output:

535714290

result:

ok single line: '535714290'

Test #5:

score: 5
Accepted
time: 5ms
memory: 3872kb

input:

14 13 0
2 9
1 2
1 3
3 8
6 11
2 7
1 5
5 12
2 13
3 14
3 10
3 6
2 4

output:

700595243

result:

ok single line: '700595243'

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 3964kb

input:

14 13 14
9 11
2 9
5 10
4 6
10 13
2 3
2 7
4 12
2 4
3 8
7 14
3 5
1 2

output:


result:

wrong answer 1st lines differ - expected: '465070080', found: ''

Test #7:

score: 5
Accepted
time: 0ms
memory: 3752kb

input:

13 0 13

output:

1

result:

ok single line: '1'

Test #8:

score: 5
Accepted
time: 1ms
memory: 4316kb

input:

14 91 14
3 4
2 10
3 10
1 13
6 8
5 6
10 13
7 8
4 9
4 7
3 7
13 14
2 12
1 3
6 9
9 14
1 10
2 9
7 11
9 11
3 12
8 10
4 13
5 9
11 12
5 14
8 12
8 13
5 13
1 5
6 11
9 13
2 5
1 14
7 14
4 14
3 5
5 11
6 12
1 2
7 10
1 4
1 8
6 10
3 8
6 13
10 14
7 12
10 11
2 13
8 11
11 13
6 7
10 12
3 14
4 5
1 6
2 14
5 10
8 14
4 8
1...

output:

4362623

result:

ok single line: '4362623'

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 3636kb

input:

9 15 9
1 2
3 5
2 8
4 8
1 4
2 5
2 7
4 5
1 9
6 8
6 9
1 3
3 7
5 9
5 8

output:


result:

wrong answer 1st lines differ - expected: '426526937', found: ''

Test #10:

score: 0
Wrong Answer
time: 0ms
memory: 3764kb

input:

9 14 9
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
4 5
6 8
4 7
6 7
3 8
4 6

output:


result:

wrong answer 1st lines differ - expected: '214820829', found: ''

Test #11:

score: 5
Accepted
time: 2ms
memory: 3852kb

input:

13 68 0
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
5 6
5 7
5 8
5 9
5 10
5 11
5 12
5 13
6 7
6 8
6 9
6 10
6 11
6 12
6 13
7 8
7 10
7 11
7 12
7 13
8 13
9 10
9 11
9 12
9 13...

output:

65784302

result:

ok single line: '65784302'

Test #12:

score: 0
Wrong Answer
time: 0ms
memory: 3996kb

input:

13 39 13
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
4 8
4 9
4 10
4 12
4 13
5 6
5 7
5 10
5 11
5 13
6 7
6 11
6 13
8 9
8 12
8 13
11 13

output:


result:

wrong answer 1st lines differ - expected: '361557272', found: ''

Test #13:

score: 0
Wrong Answer
time: 0ms
memory: 3716kb

input:

14 11 14
2 13
4 11
4 14
5 14
6 9
6 14
7 11
9 14
10 12
10 14
12 14

output:


result:

wrong answer 1st lines differ - expected: '696132576', found: ''

Test #14:

score: 0
Wrong Answer
time: 0ms
memory: 4004kb

input:

14 46 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 9
2 10
2 11
2 13
2 14
3 4
3 6
3 10
3 11
3 12
3 13
3 14
4 6
4 10
4 11
4 12
4 13
4 14
5 7
5 8
5 9
5 11
5 13
5 14
7 8
7 9
7 14
10 11
10 13
10 14
11 13
11 14
13 14

output:


result:

wrong answer 1st lines differ - expected: '258614192', found: ''

Test #15:

score: 0
Wrong Answer
time: 0ms
memory: 3716kb

input:

14 70 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 3
2 4
2 5
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
3 11
3 13
3 14
4 5
4 7
4 8
4 10
4 11
4 12
4 13
4 14
5 7
5 8
5 10
5 12
5 13
5 14
6 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
7 8
7 10
7 12
7 13
7 14
8 10
8 12
8 13
8 14
9 11
9 12
9 13
9 14
10 1...

output:


result:

wrong answer 1st lines differ - expected: '209616080', found: ''

Test #16:

score: 0
Wrong Answer
time: 0ms
memory: 3712kb

input:

14 69 14
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 3
2 5
2 6
2 7
2 9
2 10
2 11
2 12
2 13
2 14
3 5
3 6
3 7
3 9
3 10
3 11
3 12
3 13
3 14
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
5 6
5 7
5 9
5 10
5 11
5 12
5 13
5 14
6 7
6 9
6 10
6 11
6 12
6 13
6 14
7 9
7 10
7 11
7 12
7 13
7 14
8 12
8 13
8 14
9 10
...

output:


result:

wrong answer 1st lines differ - expected: '701202127', found: ''

Test #17:

score: 0
Wrong Answer
time: 0ms
memory: 3604kb

input:

14 15 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
4 6
5 9

output:


result:

wrong answer 1st lines differ - expected: '263013541', found: ''

Test #18:

score: 0
Wrong Answer
time: 0ms
memory: 3964kb

input:

15 17 15
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
3 13
3 15
13 15

output:


result:

wrong answer 1st lines differ - expected: '963180835', found: ''

Test #19:

score: 0
Wrong Answer
time: 0ms
memory: 3604kb

input:

15 17 15
1 2
1 3
1 4
1 5
1 6
1 7
1 12
1 15
7 12
7 15
8 15
9 15
10 15
11 15
12 15
13 15
14 15

output:


result:

wrong answer 1st lines differ - expected: '722208430', found: ''

Test #20:

score: 0
Wrong Answer
time: 0ms
memory: 3772kb

input:

15 16 15
1 2
1 3
1 10
2 10
3 10
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
4 15

output:


result:

wrong answer 1st lines differ - expected: '560801339', found: ''