QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#517635#8325. 重塑时光kymmykym15 0ms3804kbC++141.4kb2024-08-13 12:50:172024-08-13 12:50:18

Judging History

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

  • [2024-08-13 12:50:18]
  • 评测
  • 测评结果:15
  • 用时:0ms
  • 内存:3804kb
  • [2024-08-13 12:50:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1'000'000'007;
const int maxn=20;
int n,m,k;
int par[maxn]; 
vector<int>adj[maxn];
vector<int>tadj[maxn];
int in[maxn];
int sz[maxn];
int F[maxn];
int col[maxn];
bool bad=0;
void check(int x){
	if(col[x] == 2){
		bad=1;
		return;
	}
	if(col[x] == 1)return;
	col[x]=2;
	for(auto v:adj[x]){
		check(v);
	}
	col[x]=1;
}
	
void pre(int x){
	sz[x]=1;
	for(auto v:adj[x]){
		pre(v);
		sz[x]+=sz[v];
	}
}
int qexp(int a, int b){
	int res=1;
	while(b){
		if(b&1)res=res*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return res;
}
int inv(int x){
	return qexp(x,mod-2);
}
int dfs(int x){
	int N = sz[x];
	int res = 1;
	for(auto v:adj[x]){
		res=(res*dfs(v))%mod;
	}
	int ways=F[N-1];
	for(auto v:adj[x]){
		ways=(ways*inv(F[sz[v]]))%mod;
	}
	return res*ways%mod;
}
int32_t main(){
	F[0]=1;
	for(int i=1;i<maxn;i++){
		F[i]=F[i-1]*i%mod;
	}
	cin>>n>>m>>k;
	for(int i=1;i<=m;i++){
		int a,b;cin>>a>>b;
		in[b]++;
		tadj[a].push_back(b);
	}
	for(int i=1;i<=n;i++){
		if(in[i] == 0){
			tadj[0].push_back(i);
			in[i]++;
		}
	}
	queue<int>qu;
	qu.push(0);
	while(qu.size()){
		int cur=qu.front();qu.pop();
		for(auto v:tadj[cur]){
			in[v]--;
			if(in[v]==0){
				adj[cur].push_back(v);
				qu.push(v);
			}
		}
	}
	int rt=0;
	pre(rt);
	cout<<dfs(rt)*inv(F[n])%mod;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

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

input:

3 2 0
1 2
1 3

output:

333333336

result:

ok single line: '333333336'

Test #2:

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

input:

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

output:

425000003

result:

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

Test #3:

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

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:

153846155

result:

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

Test #4:

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

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:

71428572

result:

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

Test #5:

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

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: 3600kb

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:

530784497

result:

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

Test #7:

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

input:

13 0 13

output:

1

result:

ok single line: '1'

Test #8:

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

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:

320774361

result:

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

Test #9:

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

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:

808333339

result:

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

Test #10:

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

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:

274074076

result:

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

Test #11:

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

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:

767750750

result:

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

Test #12:

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

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:

581305851

result:

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

Test #13:

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

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:

520833337

result:

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

Test #14:

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

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:

979915150

result:

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

Test #15:

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

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:

673199439

result:

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

Test #16:

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

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:

474663470

result:

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

Test #17:

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

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:

17857143

result:

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

Test #18:

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

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:

411111114

result:

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

Test #19:

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

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:

685185190

result:

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

Test #20:

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

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:

102272728

result:

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