QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#608924#9414. Colorful Spanning Treeorz_zAC ✓52ms13940kbC++143.7kb2024-10-04 09:15:112024-10-04 09:15:12

Judging History

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

  • [2024-10-04 09:15:12]
  • 评测
  • 测评结果:AC
  • 用时:52ms
  • 内存:13940kb
  • [2024-10-04 09:15:11]
  • 提交

answer

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("Ofast,fast-math")
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {
	cerr << "[" << s << "] = [" << x << "]\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {
	for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;
	else if (s[i] == ')' || s[i] == '}') b--;
	else if (s[i] == ',' && b == 0) {
		cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";
		debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);
		break;
	}
}
#ifdef ONLINE_JUDGE
#define Debug(...)
#else
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
	int x = 0;
	bool t = 0;
	char c = getchar();
	while (c < '0' || c > '9') t |= c == '-', c = getchar();
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	return t ? -x : x;
}
inline void wi(int x) {
	if (x < 0) {
		putchar('-'), x = -x;
	}
	if (x > 9) wi(x / 10);
	putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
	wi(x), putchar(s);
}
bool Mbe;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3f;
const int _ = 2e5 + 5;

int n, b[1005][1005], a[_];

int fa[_];

vi g[_];

int find(int x) {
	return fa[x] ==x ? x : fa[x] = find(fa[x]);
}

void merge(int x, int y) {
	x = find(x), y = find(y);
	if(x == y) return;
	if(g[x].size() > g[y].size()) swap(x, y);
	for(int v : g[x]) g[y].pb(v);
	fa[x] = y;
	g[x].clear();
	g[x].shrink_to_fit();
}

void solve() {
	n = ri();
	F(i, 1, n) a[i] = ri();
	F(i, 1, n) F(j, 1, n) b[i][j] = ri();
	ll ans = 0;
	F(i, 1, n) g[i].clear();
	F(i, 1, n) fa[i] = i, g[i].pb(i);
	F(i, 1, n) {
		pii mn = {inf, 0};
		F(j, 1, n) mn = min(mn, make_pair(b[i][j], j));
		Debug(i, a[i], mn.fi, mn.se);
		assert(mn.se);
		if(find(i) != find(mn.se)) ans += 1ll * (a[i]) * mn.fi;
		else ans += 1ll * (a[i] - 1) * mn.fi;
		merge(i, mn.se);
		
	}
	vi A;
	F(z, 1, 10) {
	F(i, 1, n) if(find(i) == i) {
		Debug(i, find(2));
		pii mn = make_pair(inf, 0);
		for(int v1 : g[i]) {
			Debug(v1);
			F(j, 1, n) if(find(v1) != find(j)) mn = min(mn, make_pair(b[v1][j], j));
		}
		if(mn.fi != inf) {
			ans += mn.fi;
			merge(i, mn.se);
		}
	}
	}
	cout << ans << '\n';
}
bool Med;
signed main() {
	// Mry;
	int T = ri();
	while(T--) {
		solve();
	}
	// Try;
	return 0;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 10632kb

input:

3
3
100 1 1
1 100 2
100 100 1
2 1 100
2
3 3
100 1
1 100
1
1
5

output:

102
5
0

result:

ok 3 lines

Test #2:

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

input:

10
10
423704 592824 27840 274886 607098 178114 376416 598539 311647 319374
7 1 6 2 7 7 7 1 3 6
1 4 4 3 4 6 6 10 6 6
6 4 7 2 9 7 6 7 8 3
2 3 2 1 9 4 10 1 9 1
7 4 9 9 1 10 9 3 1 6
7 6 7 4 10 2 3 3 4 6
7 6 6 10 9 3 3 10 8 4
1 10 7 1 3 3 10 1 5 3
3 6 8 9 1 4 8 5 4 4
6 6 3 1 6 6 4 3 4 4
10
146319 989990 ...

output:

4669230
6320908
5505634
7338341
10512170
6738719
5318877
7037978
4567840
6587785

result:

ok 10 lines

Test #3:

score: 0
Accepted
time: 3ms
memory: 11404kb

input:

10
100
11072 941183 694332 268682 389214 529777 252053 968012 879706 899119 88543 610104 473604 705769 793550 498230 20570 170078 291215 624319 609362 459686 256446 721125 296148 822441 45936 179339 448830 818854 730859 665257 709087 517421 277481 817865 785020 697893 678169 839693 187917 666247 539...

output:

51748129
51863411
50650496
52453479
52565638
53840751
50481813
49287989
47805216
50158646

result:

ok 10 lines

Test #4:

score: 0
Accepted
time: 45ms
memory: 13864kb

input:

1
1000
478122 95742 782511 880731 872093 607396 190381 17329 925116 958864 337534 485465 757682 880191 77079 993960 508382 91200 159136 738826 564305 695415 711670 511675 208212 807644 837609 9612 998560 839994 242047 236580 902307 468848 969135 452732 357506 68595 639655 739298 397969 334602 724871...

output:

505683883

result:

ok single line: '505683883'

Test #5:

score: 0
Accepted
time: 46ms
memory: 13800kb

input:

1
999
581001 672148 395336 239635 709775 534619 325936 716357 131835 978865 416164 559310 998243 744344 835291 119586 235582 981781 868335 24376 959400 7345 630429 811466 597473 949112 83273 395033 309902 628285 64119 273256 92151 904148 67411 457852 535111 981847 15146 661410 357840 561570 565487 7...

output:

518451958

result:

ok single line: '518451958'

Test #6:

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

input:

100
10
880787 821040 18323 243137 618744 701509 439704 388397 92485 806138
5 5 4 3 1 10 8 7 3 3
5 10 7 9 1 6 10 2 3 8
4 7 4 6 4 4 4 5 3 2
3 9 6 1 5 9 8 1 6 6
1 1 4 5 6 10 7 3 3 7
10 6 4 9 10 8 5 5 2 9
8 10 4 8 7 5 7 3 5 2
7 2 5 1 3 5 3 3 1 5
3 3 3 6 3 2 5 1 4 9
3 8 2 6 7 9 2 5 9 1
10
961277 440894 5...

output:

6169802
6871692
9310725
6482372
7938031
4951313
5419684
6208185
8074456
9572332
11577728
15951243
6513482
6029764
9566447
9861818
5190390
5878190
7452813
8269661
7108466
5765643
5390095
8704926
12301438
6707417
5797233
10679038
9503592
4883538
6776890
8210207
7959312
11970825
5097976
8610234
7400154...

result:

ok 100 lines

Test #7:

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

input:

200
5
441424 125733 693303 689638 27750
9 5 7 7 2
5 3 6 7 3
7 6 6 6 2
7 7 6 6 8
2 3 2 8 5
5
152242 293137 31960 464656 246059
5 5 8 4 6
5 3 7 4 1
8 7 8 10 3
4 4 10 9 5
6 1 3 5 1
5
736691 503087 186672 978216 985818
4 3 6 10 4
3 4 6 8 9
6 6 10 8 3
10 8 8 1 4
4 9 3 4 5
5
909584 647057 700716 282944 82...

output:

6839979
3102667
8215021
4346990
5235477
3334893
2811233
2271079
7841993
3561461
6523534
8403645
3605735
4602948
4327930
3781964
1458882
8447332
6552420
3734471
5861497
3882903
8061292
2873041
2187091
7223752
8626264
3953465
7000712
8143948
3902031
5628392
9492241
3708587
5194828
9813350
3091731
8421...

result:

ok 200 lines

Test #8:

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

input:

10
10
641200 704686 625840 4639 466329 869192 44444 925112 233549 544182
812952 543505 248565 721077 834394 705087 909041 596564 504331 629166
543505 322835 99383 908934 977178 59362 876437 968285 299220 948952
248565 99383 230843 947540 27587 823525 317832 143268 279392 801385
721077 908934 947540 ...

output:

464575391845
722792766204
603423893959
689171505048
568050207448
141189280594
398352676365
553331086822
358368405765
466545011258

result:

ok 10 lines

Test #9:

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

input:

10
100
300485 597410 31772 709441 569794 603871 940402 115019 464242 819978 205173 825880 175487 192620 357134 409216 61048 698768 730576 980321 457742 744836 459502 73307 373592 500956 64512 610389 56591 55215 837763 780406 620499 22680 574421 621100 350308 479030 985533 478697 895337 373164 92129 ...

output:

427429078356
437107249185
388846042680
568445876406
548124289689
504287030506
367473750374
383934281073
474237182179
517071986601

result:

ok 10 lines

Test #10:

score: 0
Accepted
time: 52ms
memory: 13816kb

input:

1
1000
293326 400584 892744 489086 373601 391092 679 371497 324446 378078 346596 402455 12885 313634 577136 645016 141114 183970 700706 343551 785701 457859 760179 834082 70994 861742 994563 784029 622754 397392 940754 353872 324441 672282 477639 691741 237342 420417 626477 348331 348221 279615 9112...

output:

495242927744

result:

ok single line: '495242927744'

Test #11:

score: 0
Accepted
time: 50ms
memory: 13932kb

input:

1
999
813093 578797 362902 332759 65558 57845 262551 806163 608236 596036 917220 151190 931483 63430 987211 655670 640617 983837 719278 520318 92339 957276 587137 242796 353192 919052 971727 684724 834764 775914 934518 827771 982327 153127 437734 97436 39764 455911 268837 907495 345506 309955 256078...

output:

515134600851

result:

ok single line: '515134600851'

Test #12:

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

input:

100
10
179602 985361 548892 631822 631466 746042 927697 22571 215251 944618
921094 842946 924663 729594 836619 520799 160423 584262 775633 936080
842946 2519 921583 547439 88105 614623 670683 738974 556545 545403
924663 921583 549300 644542 861683 704652 355109 226127 250398 356118
729594 547439 644...

output:

333841806589
441383974753
410108681066
193033096684
882858367324
372418727791
475337397010
223606988129
474140279002
276834109836
766114000758
303602034921
374090175057
487095871865
599524192316
457216561537
316096831128
599101634544
424328348923
465156925375
621746687865
678160751784
905811140862
6...

result:

ok 100 lines

Test #13:

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

input:

200
5
862689 960290 678911 376902 964053
259551 342565 813017 485184 428811
342565 115979 16156 401669 293538
813017 16156 595912 251467 546382
485184 401669 251467 163840 519350
428811 293538 546382 519350 204231
5
786184 950120 519286 31315 814884
100672 164842 736855 887448 102931
164842 921210 4...

output:

509036099710
336770463691
115367297940
551160805285
757292917029
496724995269
537864130580
88440912772
394600480843
964461115488
343680016687
348528313837
313879957218
439376646847
302075313264
291690230142
762782325567
205429564431
396690894510
272338766522
715949911886
502087969345
224814484890
39...

result:

ok 200 lines

Test #14:

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

input:

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

output:

70
103
50
69
85
76
78
63
122
57

result:

ok 10 lines

Test #15:

score: 0
Accepted
time: 6ms
memory: 10808kb

input:

10
100
6 9 8 1 10 8 4 1 4 3 5 10 8 8 2 3 4 7 3 3 3 9 8 4 8 9 3 8 2 5 9 6 6 6 3 3 8 4 2 4 8 3 10 2 8 8 6 10 7 5 1 5 9 2 8 6 9 9 3 9 3 2 8 5 9 9 5 8 1 10 5 8 4 1 4 10 7 3 1 9 8 2 8 4 6 3 8 9 10 2 2 10 1 6 5 1 1 3 7 5
4 4 1 4 9 3 9 8 8 10 10 5 4 3 4 8 5 10 4 7 6 10 7 6 10 8 10 2 8 7 5 4 7 3 8 5 1 5 9 5...

output:

557
546
537
524
489
548
528
568
523
534

result:

ok 10 lines

Test #16:

score: 0
Accepted
time: 43ms
memory: 13940kb

input:

1
1000
8 8 4 2 10 3 8 7 9 8 4 5 4 6 5 2 5 9 5 5 1 7 2 3 7 9 6 5 7 10 5 1 9 3 6 6 4 2 1 2 9 6 7 6 3 5 9 10 2 7 7 5 9 9 8 10 5 9 8 8 2 7 9 6 6 6 10 2 2 3 3 8 3 5 9 8 8 8 7 1 1 7 3 3 1 9 8 3 4 5 8 6 1 4 3 4 1 2 1 1 10 1 3 10 9 6 10 2 1 7 9 5 2 10 4 4 5 10 7 8 10 3 7 2 4 10 1 4 1 7 8 5 3 9 6 3 8 7 1 10 ...

output:

5535

result:

ok single line: '5535'

Test #17:

score: 0
Accepted
time: 35ms
memory: 13800kb

input:

1
999
2 3 9 3 3 10 7 10 6 7 8 6 2 8 9 6 10 2 7 10 1 9 9 1 9 1 8 9 3 1 7 3 1 3 4 8 1 8 1 2 10 7 3 2 8 4 5 1 3 1 2 8 6 8 2 8 5 5 3 3 5 3 4 9 4 2 9 5 4 8 3 4 8 7 1 7 4 6 3 3 2 9 6 4 9 2 5 2 4 10 5 5 6 9 4 9 3 3 10 5 8 4 1 2 1 5 8 3 5 10 7 2 4 6 7 2 6 8 8 1 9 5 4 10 5 3 2 1 4 1 5 2 2 8 1 8 6 4 3 3 3 8 2...

output:

5552

result:

ok single line: '5552'

Test #18:

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

input:

100
10
6 8 4 1 10 9 7 3 4 5
9 4 9 5 6 4 6 7 4 8
4 1 9 4 2 3 9 10 1 6
9 9 2 7 7 7 2 10 8 5
5 4 7 8 9 10 8 8 8 8
6 2 7 9 5 7 2 2 9 1
4 3 7 10 7 2 4 6 3 2
6 9 2 8 2 4 10 3 9 9
7 10 10 8 2 6 3 1 5 8
4 1 8 8 9 3 9 5 9 9
8 6 5 8 1 2 9 8 9 4
10
2 10 8 2 3 7 3 2 6 8
6 5 6 2 1 8 4 10 8 5
5 8 7 9 1 2 5 7 2 7
...

output:

99
82
127
106
84
82
102
71
79
90
151
129
75
80
73
101
57
51
57
58
108
73
78
102
62
71
92
128
54
111
54
113
63
115
95
58
72
55
73
101
55
63
58
82
117
50
93
70
82
86
87
77
91
81
65
79
79
62
57
103
86
87
74
128
84
91
108
95
87
111
92
95
59
57
60
99
84
58
100
86
96
69
46
124
69
97
80
89
87
85
82
48
102
...

result:

ok 100 lines

Test #19:

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

input:

200
5
2 10 2 7 1
6 10 10 9 2
10 7 10 1 7
10 10 8 7 8
9 1 7 3 10
2 7 8 10 10
5
8 2 10 8 5
2 8 2 7 9
8 5 6 3 1
2 6 1 10 9
7 3 10 3 7
9 1 9 7 9
5
2 9 8 10 7
7 6 1 2 5
6 8 7 7 6
1 7 1 3 10
2 7 3 9 3
5 6 10 3 2
5
2 5 8 1 7
1 2 9 9 9
2 1 6 1 3
9 6 4 3 2
9 1 3 8 5
9 3 2 5 7
5
1 4 10 1 4
3 5 10 4 2
5 7 6 7 ...

output:

41
61
98
39
82
36
128
78
54
46
140
44
44
68
32
32
34
46
59
90
45
41
28
89
44
41
85
70
92
24
35
56
44
62
26
62
43
78
41
58
64
77
99
25
70
32
122
48
39
65
41
27
32
46
103
47
40
25
86
29
47
48
37
54
65
95
74
55
43
67
56
46
41
103
68
107
103
51
122
57
22
39
130
34
126
68
33
92
42
89
130
60
57
55
43
50
7...

result:

ok 200 lines

Test #20:

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

input:

1
1
100
1

output:

99

result:

ok single line: '99'

Extra Test:

score: 0
Extra Test Passed