QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#859718#7135. Chromatic NumberC1942huangjiaxuAC ✓114ms21344kbC++142.1kb2025-01-17 22:08:172025-01-17 22:08:24

Judging History

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

  • [2025-01-17 22:08:24]
  • 评测
  • 测评结果:AC
  • 用时:114ms
  • 内存:21344kb
  • [2025-01-17 22:08:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,P=1e9+7;
int n,m,c,f[N][3],pw[N],ans=1,id[N];
int dp[1<<16],g[1<<16],h[1<<16],va[21],lb[1<<16];
multiset<pair<int,int> >e[N];
bool vis[N];
queue<int>q;
vector<int>vc;
inline void Add(int &x,int y){
	if((x+=y)>=P)x-=P;
}
void init(){
	f[0][1]=f[0][2]=pw[0]=1;
	for(int i=1;i<=n;++i){
		f[i][0]=pw[i]=1ll*(c-1)*pw[i-1]%P;
		f[i][1]=f[i-1][0];
		Add(f[i][0],P-f[i][1]);
		f[i][2]=(1ll*f[i-1][2]*(c-2)+f[i][1])%P;
	}
	for(int i=1;i<=n;++i)if(e[i].size()<3)vis[i]=true,q.push(i);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		if(e[u].empty()){
			ans=1ll*c*ans%P;
			printf("%d\n",ans);
			exit(0);
		}
		if(e[u].size()==1){
			auto [x,y]=*e[u].begin();
			ans=1ll*ans*pw[y]%P;
			e[x].erase(e[x].find({u,y}));
			if(e[x].size()<3&&!vis[x])q.push(x),vis[x]=true;
		}else{
			auto [x1,y1]=*e[u].begin();
			auto [x2,y2]=*e[u].rbegin();
			e[x1].erase(e[x1].find({u,y1}));
			e[x2].erase(e[x2].find({u,y2}));
			if(x1==x2)ans=1ll*ans*f[y1+y2][1]%P;
			else{
				e[x1].emplace(x2,y1+y2);
				e[x2].emplace(x1,y1+y2);
			}
		}
	}
}
void DP(){
	for(int i=1;i<=n;++i)if(!vis[i])id[i]=vc.size(),vc.emplace_back(i);
	m=vc.size();
	for(int S=1;S<1<<m;++S){
		for(int j=m-1;~j;--j)if(S>>j&1)lb[S]=j;
		h[S]=1;
		for(int j=0;j<m;++j)if(S>>j&1)
			for(auto [x,y]:e[vc[j]])if(id[x]>j&&(S>>id[x]&1))h[S]=1ll*h[S]*f[y][1]%P;
	}
	dp[0]=g[0]=1;
	int res=0;
	for(int i=1,fac=1;i<=m;++i){
		for(int S=(1<<m)-1;~S;--S)if(dp[S]){
			int U=(1<<m)-1^S;
			for(int j=0;j<m;++j)if(U>>j&1){
				va[j]=1;
				for(auto [x,y]:e[vc[j]])if(S>>id[x]&1)va[j]=1ll*va[j]*f[y-1][2]%P;
			}
			for(int T=U,W;;T=(T-1)&U){
				W=U^T;
				if(W)g[W]=1ll*g[W^(1<<lb[W])]*va[lb[W]]%P;
				if(!(T>>lb[U]&1))Add(dp[S|W],1ll*g[W]*h[W]%P*dp[S]%P);
				if(!T)break;
			}
			dp[S]=0;
		}
		fac=1ll*fac*(c-i+1)%P;
		Add(res,1ll*fac*dp[(1<<m)-1]%P);
	}
	printf("%d\n",1ll*ans*res%P);
}
int main(){
	scanf("%d%d%d",&n,&m,&c);
	for(int i=1,x,y;i<=m;++i){
		scanf("%d%d",&x,&y);
		if(e[x].find({y,1})!=e[x].end())continue;
		e[x].emplace(y,1);
		e[y].emplace(x,1);
	}
	init();
	DP();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 11516kb

input:

3 3 3
1 2
2 3
3 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 1ms
memory: 11472kb

input:

4 3 1000000000
1 2
2 3
3 4

output:

3584

result:

ok 1 number(s): "3584"

Test #3:

score: 0
Accepted
time: 0ms
memory: 9484kb

input:

10 9 115762598
9 3
5 2
7 2
4 10
9 5
6 5
10 5
1 9
6 8

output:

362262637

result:

ok 1 number(s): "362262637"

Test #4:

score: 0
Accepted
time: 0ms
memory: 10756kb

input:

10 9 232918561
9 3
4 5
1 8
3 1
7 3
2 3
10 3
10 6
4 8

output:

389774226

result:

ok 1 number(s): "389774226"

Test #5:

score: 0
Accepted
time: 0ms
memory: 10332kb

input:

10 9 499817628
1 9
8 7
4 1
2 6
5 10
9 3
1 2
7 3
5 4

output:

277296172

result:

ok 1 number(s): "277296172"

Test #6:

score: 0
Accepted
time: 1ms
memory: 11324kb

input:

10 9 911940886
6 2
3 9
9 7
9 5
6 10
8 5
5 4
3 1
2 3

output:

184420559

result:

ok 1 number(s): "184420559"

Test #7:

score: 0
Accepted
time: 2ms
memory: 10696kb

input:

10 9 883872657
7 3
1 3
6 5
4 8
6 2
8 6
1 2
9 6
6 10

output:

366398529

result:

ok 1 number(s): "366398529"

Test #8:

score: 0
Accepted
time: 1ms
memory: 9552kb

input:

10 9 295995916
10 9
4 5
1 5
6 4
2 10
8 7
10 4
8 3
4 3

output:

837491197

result:

ok 1 number(s): "837491197"

Test #9:

score: 0
Accepted
time: 0ms
memory: 11428kb

input:

10 9 562894982
5 4
10 7
10 8
1 9
6 10
10 3
2 7
5 10
3 1

output:

525028615

result:

ok 1 number(s): "525028615"

Test #10:

score: 0
Accepted
time: 1ms
memory: 10072kb

input:

10 9 680050945
1 7
4 1
2 9
4 3
8 1
2 1
10 9
5 10
6 4

output:

124441014

result:

ok 1 number(s): "124441014"

Test #11:

score: 0
Accepted
time: 1ms
memory: 9796kb

input:

10 9 946950012
10 8
4 7
6 2
10 6
10 5
6 9
4 1
10 3
4 10

output:

20956316

result:

ok 1 number(s): "20956316"

Test #12:

score: 0
Accepted
time: 0ms
memory: 10100kb

input:

10 9 506357456
3 7
6 2
10 6
5 6
8 4
8 2
3 5
9 2
1 6

output:

86924456

result:

ok 1 number(s): "86924456"

Test #13:

score: 0
Accepted
time: 0ms
memory: 11492kb

input:

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

output:

963016414

result:

ok 1 number(s): "963016414"

Test #14:

score: 0
Accepted
time: 1ms
memory: 10632kb

input:

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

output:

571949872

result:

ok 1 number(s): "571949872"

Test #15:

score: 0
Accepted
time: 0ms
memory: 9572kb

input:

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

output:

777872763

result:

ok 1 number(s): "777872763"

Test #16:

score: 0
Accepted
time: 0ms
memory: 11328kb

input:

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

output:

955339809

result:

ok 1 number(s): "955339809"

Test #17:

score: 0
Accepted
time: 1ms
memory: 10856kb

input:

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

output:

694067238

result:

ok 1 number(s): "694067238"

Test #18:

score: 0
Accepted
time: 1ms
memory: 10636kb

input:

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

output:

185923214

result:

ok 1 number(s): "185923214"

Test #19:

score: 0
Accepted
time: 0ms
memory: 9792kb

input:

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

output:

184017713

result:

ok 1 number(s): "184017713"

Test #20:

score: 0
Accepted
time: 2ms
memory: 9676kb

input:

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

output:

965241046

result:

ok 1 number(s): "965241046"

Test #21:

score: 0
Accepted
time: 1ms
memory: 11548kb

input:

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

output:

557918302

result:

ok 1 number(s): "557918302"

Test #22:

score: 0
Accepted
time: 0ms
memory: 10616kb

input:

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

output:

510658328

result:

ok 1 number(s): "510658328"

Test #23:

score: 0
Accepted
time: 1ms
memory: 11176kb

input:

10 18 41678757
6 9
7 4
8 5
3 10
9 3
7 2
10 1
3 6
10 8
3 1
8 6
6 5
1 8
8 2
9 2
9 7
10 5
5 2

output:

232344468

result:

ok 1 number(s): "232344468"

Test #24:

score: 0
Accepted
time: 0ms
memory: 10020kb

input:

10 18 453802016
2 10
3 1
3 6
7 9
4 2
6 5
6 2
10 9
9 3
3 6
7 2
5 2
4 9
1 10
1 9
3 1
8 4
9 2

output:

662941207

result:

ok 1 number(s): "662941207"

Test #25:

score: 0
Accepted
time: 1ms
memory: 11496kb

input:

10 18 425733787
8 4
2 10
5 2
9 6
3 1
7 5
10 2
10 1
9 4
3 8
5 6
4 3
10 5
1 6
4 7
8 10
7 2
10 6

output:

668745834

result:

ok 1 number(s): "668745834"

Test #26:

score: 0
Accepted
time: 0ms
memory: 11028kb

input:

10 18 837857046
5 4
7 2
7 5
7 3
7 6
10 5
3 2
3 10
1 10
10 3
7 8
1 10
4 7
6 7
9 5
7 10
7 1
8 9

output:

668666637

result:

ok 1 number(s): "668666637"

Test #27:

score: 0
Accepted
time: 0ms
memory: 11180kb

input:

10 18 104756112
3 1
4 8
8 3
1 7
9 2
1 5
2 5
8 7
8 7
6 7
7 3
7 3
5 8
7 9
8 4
4 6
5 7
10 7

output:

183542868

result:

ok 1 number(s): "183542868"

Test #28:

score: 0
Accepted
time: 1ms
memory: 9912kb

input:

10 18 221912075
6 3
8 6
6 3
7 6
1 7
2 4
9 1
10 6
4 5
10 7
8 7
2 6
10 5
4 3
3 5
8 7
8 10
6 2

output:

761268497

result:

ok 1 number(s): "761268497"

Test #29:

score: 0
Accepted
time: 1ms
memory: 11444kb

input:

10 18 488811142
1 6
2 8
9 6
7 5
8 3
1 2
4 9
3 9
8 2
6 5
10 5
10 1
4 9
1 2
1 2
6 8
8 10
9 3

output:

936252081

result:

ok 1 number(s): "936252081"

Test #30:

score: 0
Accepted
time: 0ms
memory: 11172kb

input:

10 18 900934400
3 10
6 7
3 2
2 6
4 8
7 9
7 2
5 3
6 10
1 6
2 9
9 2
4 6
4 3
2 8
4 3
3 1
5 2

output:

360645711

result:

ok 1 number(s): "360645711"

Test #31:

score: 0
Accepted
time: 0ms
memory: 10140kb

input:

10 18 872866171
8 9
3 4
2 4
10 1
6 5
2 9
2 10
1 6
7 10
4 3
1 4
2 6
3 9
8 6
5 9
10 1
3 9
3 2

output:

135238219

result:

ok 1 number(s): "135238219"

Test #32:

score: 0
Accepted
time: 0ms
memory: 11540kb

input:

10 18 727240911
2 3
8 1
5 3
8 3
1 9
8 2
3 6
6 7
7 2
6 10
5 9
1 4
10 9
4 1
9 2
7 5
10 7
8 9

output:

625599117

result:

ok 1 number(s): "625599117"

Test #33:

score: 0
Accepted
time: 97ms
memory: 21288kb

input:

100000 99999 216582436
67887 20146
27747 62083
8124 33065
41260 53150
42021 3802
87356 57772
83031 40355
60565 85274
48531 88298
9396 81200
82576 71260
95399 65850
60833 14965
92028 51237
33279 5157
51196 43754
33099 43391
98642 66920
22716 76942
63091 64560
91789 79633
5578 26187
70166 40246
28618 ...

output:

223041049

result:

ok 1 number(s): "223041049"

Test #34:

score: 0
Accepted
time: 96ms
memory: 21328kb

input:

100000 99999 537935470
52946 52293
51352 59202
95213 33648
36910 82735
81990 6030
83398 35329
82555 32255
42194 64554
97246 13898
81653 61302
17544 23827
63502 87643
85605 47799
67046 59093
50860 47709
11595 73145
41218 78648
48849 87740
94198 23708
51514 74478
75948 78610
9930 39276
27596 58641
965...

output:

683754071

result:

ok 1 number(s): "683754071"

Test #35:

score: 0
Accepted
time: 95ms
memory: 20876kb

input:

100000 99999 419097015
77940 95356
17188 49000
54612 86308
75600 91149
51974 2890
41007 96880
96769 34874
73768 13836
54745 70679
49696 40272
36534 12110
88352 94339
76124 65044
15265 86673
61325 68059
64923 33404
99939 90159
37608 44149
89390 62182
82437 60047
13256 82426
23143 36854
46756 6478
970...

output:

570516850

result:

ok 1 number(s): "570516850"

Test #36:

score: 0
Accepted
time: 93ms
memory: 20980kb

input:

100000 99999 595225856
70224 92526
13532 37856
83588 77194
88154 35017
89550 56435
27599 36549
45226 58315
23755 68217
6754 33564
68895 29336
68655 94732
7787 99953
68847 27403
3483 1161
94541 71377
66881 31627
91739 82582
27153 89516
40241 3914
65717 14869
41504 94830
63149 73178
72686 14238
49651 ...

output:

787011438

result:

ok 1 number(s): "787011438"

Test #37:

score: 0
Accepted
time: 92ms
memory: 21216kb

input:

100000 99999 771354698
3379 87839
94057 29719
80065 84184
48484 61868
29707 52305
2045 1128
76734 30718
93490 78947
22816 97775
34361 98900
39565 42289
43515 43000
50088 90693
50119 61936
31284 24848
55472 17464
37360 39407
86104 3614
52802 68908
92250 11924
43758 56310
49234 73934
76120 19035
87054...

output:

911425512

result:

ok 1 number(s): "911425512"

Test #38:

score: 0
Accepted
time: 98ms
memory: 21320kb

input:

100000 100004 819359296
35499 86446
51142 44306
67852 67339
66613 57695
2129 66482
99232 22293
65808 64264
9107 75763
43459 44512
22904 53756
80022 72854
56714 71002
73284 10423
88319 50633
64619 16764
58333 2464
48590 33547
42457 55203
55476 20033
73716 73429
67025 59202
38747 24730
68062 57927
349...

output:

105594652

result:

ok 1 number(s): "105594652"

Test #39:

score: 0
Accepted
time: 88ms
memory: 21088kb

input:

100000 100004 995488138
69703 90085
10989 12780
55081 23794
53465 52650
42454 76800
94270 46483
53905 33531
51364 7662
70837 77366
99256 45406
3139 73805
21594 25607
79480 60256
11420 32356
52823 84585
65372 49862
33990 91251
90859 21220
46275 79340
67392 21531
79387 66267
47719 47510
95237 78975
60...

output:

11150601

result:

ok 1 number(s): "11150601"

Test #40:

score: 0
Accepted
time: 84ms
memory: 21032kb

input:

100000 100004 876649683
95536 99866
1087 83411
50562 92660
57532 258
20329 23169
30003 67492
68126 674
12458 12345
43935 26818
66156 70866
24703 79917
49241 85961
88652 78316
37186 51857
73134 89863
76418 18191
83658 99467
73127 70687
80180 28043
25400 31639
3047 85105
96348 24986
96448 24957
36646 ...

output:

501054030

result:

ok 1 number(s): "501054030"

Test #41:

score: 0
Accepted
time: 101ms
memory: 21312kb

input:

100000 100004 52778525
66265 1221
47939 56270
43595 55036
4230 22794
44653 43504
81094 47093
51310 25542
87884 91354
11890 81564
30104 92128
78996 97439
79626 53840
30728 84799
92623 58532
75000 21702
52850 34367
65790 50845
896 93906
27733 93571
84116 94839
73763 51874
86880 44802
67206 18681
93260...

output:

825147866

result:

ok 1 number(s): "825147866"

Test #42:

score: 0
Accepted
time: 98ms
memory: 21344kb

input:

100000 100004 228907366
28291 24385
66304 70112
90762 6406
25875 56774
49259 37149
28292 63528
61191 98842
68845 65827
73231 37444
30858 6250
10954 78151
40850 2138
66913 88903
47448 12068
96495 5360
17876 17379
79944 58164
47755 44113
43203 49391
96476 37533
95520 30807
25555 71204
8520 22452
11919...

output:

565836392

result:

ok 1 number(s): "565836392"

Test #43:

score: 0
Accepted
time: 98ms
memory: 21204kb

input:

100000 100008 437465892
66983 60584
83471 77711
34305 7949
64019 10619
65263 38740
35418 76994
6499 51060
27689 69992
91372 30062
58629 42710
69198 6525
72671 34943
39090 35063
74484 33049
75757 94288
59333 93245
29903 54840
18087 27736
76649 11233
79054 24878
82958 35262
61452 77306
78255 30273
402...

output:

755152869

result:

ok 1 number(s): "755152869"

Test #44:

score: 0
Accepted
time: 100ms
memory: 21232kb

input:

100000 100008 613594733
71964 66953
29773 12510
80187 22081
874 72189
46211 70587
94814 50647
34701 6676
60368 57775
81967 44935
37653 26453
96705 83402
33637 14081
54062 79626
20846 15393
88707 81377
59186 60487
48694 30999
94936 97665
45170 79956
46837 26548
87016 19083
31596 84129
24334 10807
955...

output:

785126567

result:

ok 1 number(s): "785126567"

Test #45:

score: 0
Accepted
time: 109ms
memory: 21272kb

input:

100000 100008 934947766
31284 45161
91440 49074
36239 5573
45456 89197
16970 5979
55618 32640
57365 7844
77920 43884
95749 57653
92079 26855
52994 33450
24184 32481
88427 16078
86380 10100
29633 2966
67744 40145
73174 32928
64478 47318
94904 79257
28366 14010
8170 75525
81690 27414
69865 37521
29422...

output:

962293857

result:

ok 1 number(s): "962293857"

Test #46:

score: 0
Accepted
time: 106ms
memory: 21344kb

input:

100000 100008 111076608
96562 21502
42716 62305
81497 89169
7350 3523
96168 32289
65623 53903
88928 36095
84801 95496
44047 80747
65434 64503
61106 47116
96029 50476
17120 71238
49467 28381
5296 11132
61222 44005
65851 26492
73707 91874
14956 60684
82505 97051
85978 11773
73678 55540
29157 88473
997...

output:

894315

result:

ok 1 number(s): "894315"

Test #47:

score: 0
Accepted
time: 114ms
memory: 21260kb

input:

100000 100008 992238153
69797 95751
10672 75314
27937 93944
51883 53807
94418 40642
68843 10642
64020 81639
36103 4452
75934 75032
5706 22879
86490 67787
92085 29896
85543 39360
12207 7993
9156 94005
10389 81110
84847 82461
9027 85402
70518 52232
48395 98386
25574 2065
20203 53872
25208 57078
28643 ...

output:

384544826

result:

ok 1 number(s): "384544826"

Extra Test:

score: 0
Extra Test Passed