QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#477720#4216. Funny SalesmanpavementAC ✓25ms9636kbC++171.9kb2024-07-14 09:11:142024-07-14 09:11:15

Judging History

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

  • [2024-07-14 09:11:15]
  • 评测
  • 测评结果:AC
  • 用时:25ms
  • 内存:9636kb
  • [2024-07-14 09:11:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define eb emplace_back

using ii = pair<int, int>;
using ll = long long;

int n;
ll ans;
vector<ii> ed[35];

namespace ufds {
	int lnk[100005], sz[100005];
	priority_queue<ii, vector<ii>, greater<ii> > pq[100005];
	
	void init(int n) {
		iota(lnk + 1, lnk + 1 + n, 1);
		fill(sz + 1, sz + 1 + n, 1);
	}
	int find(int x) {
		if (x == lnk[x]) {
			return x;
		}
		return lnk[x] = find(lnk[x]);
	}
	void unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b) {
			return;
		}
		if (sz[b] > sz[a]) {
			swap(a, b);
		}
		sz[a] += sz[b];
		lnk[b] = a;
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	ufds::init(n);
	for (int i = 1, u, v, w; i < n; i++) {
		cin >> u >> v >> w;
		ed[w].eb(u, v);
	}
	for (int w = 0; w <= 30; w++) {
		for (auto [u, v] : ed[w]) {
			int u_sz = ufds::sz[ufds::find(u)];
			int v_sz = ufds::sz[ufds::find(v)];
			if (u_sz > v_sz) {
				swap(u, v);
				swap(u_sz, v_sz);
			}
			if (u_sz == v_sz) {
				ufds::unite(u, v);
				while (!ufds::pq[ufds::find(v)].empty()) {
					ufds::pq[ufds::find(v)].pop();
				}
				ufds::pq[ufds::find(v)].emplace(w, 2 * u_sz - 1);
			} else {
				int old_rep = ufds::find(v);
				ufds::unite(u, v);
				swap(ufds::pq[ufds::find(u)], ufds::pq[old_rep]);
				// u_sz < v_sz
				for (int cur = u_sz; cur; ) {
					auto tmp = ufds::pq[ufds::find(v)].top();
					ufds::pq[ufds::find(v)].pop();
					if (tmp.second <= cur) {
						cur -= tmp.second;
					} else {
						ufds::pq[ufds::find(v)].emplace(tmp.first, tmp.second - cur);
						cur = 0;
					}
				}
				ufds::pq[ufds::find(v)].emplace(w, 2 * u_sz);
			}
		}
	}
	while (!ufds::pq[ufds::find(1)].empty()) {
		auto tmp = ufds::pq[ufds::find(1)].top();
		ufds::pq[ufds::find(1)].pop();
		ans += (1ll << tmp.first) * tmp.second;
	}
	cout << ans << '\n';
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7164kb

input:

5
1 2 0
2 3 0
3 4 0
4 5 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

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

output:

42

result:

ok 1 number(s): "42"

Test #3:

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

input:

2
2 1 20

output:

1048576

result:

ok 1 number(s): "1048576"

Test #4:

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

input:

5
4 2 25
5 4 0
5 3 16
5 1 28

output:

603979776

result:

ok 1 number(s): "603979776"

Test #5:

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

input:

8
3 2 2
3 4 27
6 3 2
1 6 9
5 7 24
8 5 23
8 1 3

output:

318767616

result:

ok 1 number(s): "318767616"

Test #6:

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

input:

4
1 2 6
4 1 26
4 3 10

output:

201326592

result:

ok 1 number(s): "201326592"

Test #7:

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

input:

3
2 1 2
2 3 3

output:

16

result:

ok 1 number(s): "16"

Test #8:

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

input:

3
1 2 10
1 3 26

output:

134217728

result:

ok 1 number(s): "134217728"

Test #9:

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

input:

10
1 4 15
6 2 23
1 7 20
1 9 29
1 3 1
6 1 4
10 6 12
8 5 13
8 10 20

output:

1095761920

result:

ok 1 number(s): "1095761920"

Test #10:

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

input:

5
2 3 2
2 5 16
4 1 14
4 2 26

output:

268435456

result:

ok 1 number(s): "268435456"

Test #11:

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

input:

9
7 8 3
3 5 13
7 3 3
2 9 20
4 2 21
1 4 0
7 1 30
6 7 14

output:

8589934592

result:

ok 1 number(s): "8589934592"

Test #12:

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

input:

4
4 3 5
2 4 25
1 2 10

output:

100663296

result:

ok 1 number(s): "100663296"

Test #13:

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

input:

3
3 1 19
3 2 22

output:

8388608

result:

ok 1 number(s): "8388608"

Test #14:

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

input:

8
2 5 13
2 4 10
6 1 14
8 2 8
6 8 8
3 7 6
6 3 8

output:

51456

result:

ok 1 number(s): "51456"

Test #15:

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

input:

2
1 2 12

output:

4096

result:

ok 1 number(s): "4096"

Test #16:

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

input:

50
47 42 17
16 28 6
37 6 22
49 2 5
49 22 0
40 10 15
36 15 3
32 36 21
38 39 8
32 45 2
4 43 14
16 37 4
48 4 9
12 49 4
8 12 19
40 8 3
34 40 8
7 41 0
44 17 4
3 11 7
16 25 17
30 16 9
18 30 30
27 38 30
20 33 8
26 7 29
48 5 10
14 48 30
21 35 13
14 47 14
27 26 15
24 27 29
29 9 11
3 29 12
18 3 6
23 46 16
20 ...

output:

34225520640

result:

ok 1 number(s): "34225520640"

Test #17:

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

input:

50
38 32 1
21 31 30
45 6 26
47 17 28
14 34 21
7 11 6
50 42 6
30 25 1
13 10 17
3 13 25
41 3 15
14 36 27
43 41 0
8 22 30
5 48 28
1 43 5
44 15 20
23 19 17
7 26 9
7 29 20
1 7 2
23 44 5
20 23 1
16 47 4
9 16 28
39 1 15
49 39 8
28 49 8
2 24 5
37 45 22
50 37 30
18 50 2
21 18 24
30 21 22
46 30 28
4 27 3
5 9 ...

output:

31675383808

result:

ok 1 number(s): "31675383808"

Test #18:

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

input:

50
13 14 2
36 11 5
37 39 27
40 29 12
44 47 15
42 50 9
20 34 6
48 13 25
9 15 19
4 35 10
19 4 14
28 38 18
7 28 9
42 45 12
40 42 4
18 49 13
32 18 19
9 32 30
48 30 4
1 48 17
37 2 14
12 7 7
6 12 30
41 10 19
22 41 9
24 22 22
24 17 20
19 24 21
20 19 16
46 40 20
43 46 8
33 43 24
6 33 23
1 6 28
27 1 23
36 3 ...

output:

52613349376

result:

ok 1 number(s): "52613349376"

Test #19:

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

input:

50
40 49 24
46 18 15
5 47 29
25 43 11
1 21 22
4 40 1
37 7 22
37 22 11
27 10 6
29 24 22
16 25 8
46 39 9
48 42 15
8 29 24
34 45 21
37 34 9
31 26 4
2 35 7
41 11 7
17 41 7
44 28 19
38 17 10
4 5 19
33 12 17
36 33 14
1 36 5
23 1 21
19 23 7
2 19 15
20 2 16
30 20 29
37 30 19
14 38 16
16 14 28
48 15 28
46 3 ...

output:

15170797568

result:

ok 1 number(s): "15170797568"

Test #20:

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

input:

50
2 39 15
38 3 29
34 26 14
46 47 17
27 9 25
1 27 28
35 30 19
32 35 28
36 46 27
34 36 26
28 12 29
49 14 29
13 1 21
7 13 26
29 7 20
48 29 2
43 42 4
40 38 27
33 2 5
21 5 27
22 23 11
15 18 8
8 15 12
10 45 10
34 6 6
33 34 23
8 33 6
20 10 22
41 28 20
32 41 5
8 49 7
20 24 13
37 20 26
48 37 22
16 17 6
4 16...

output:

10066329600

result:

ok 1 number(s): "10066329600"

Test #21:

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

input:

50
21 50 0
13 12 1
37 1 30
32 20 8
37 34 24
13 28 14
10 49 29
31 29 18
11 5 6
38 21 15
19 38 21
11 19 24
8 23 0
36 18 22
4 36 3
41 43 19
31 9 3
24 46 28
4 24 5
22 17 21
6 7 18
30 8 29
45 30 6
25 45 7
22 25 7
32 22 22
48 32 14
47 48 14
37 47 4
15 37 28
39 40 21
13 39 18
33 26 30
41 27 25
11 41 7
3 15...

output:

46976204800

result:

ok 1 number(s): "46976204800"

Test #22:

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

input:

50
41 11 6
6 38 23
9 50 28
2 39 25
27 2 16
4 30 15
20 27 11
18 24 17
1 18 19
33 26 18
40 12 26
46 40 2
3 31 20
49 44 13
7 15 28
17 23 1
9 22 6
49 7 3
36 10 13
17 36 6
28 17 25
42 28 1
46 47 8
48 46 1
9 48 12
35 9 0
20 35 17
25 20 15
29 25 7
21 29 21
16 21 16
45 41 22
5 49 22
1 37 16
1 13 5
4 14 16
6...

output:

2053111808

result:

ok 1 number(s): "2053111808"

Test #23:

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

input:

50
31 35 18
12 38 5
28 8 7
36 19 7
13 24 28
28 11 12
42 44 25
40 20 24
33 45 23
37 33 22
46 37 7
30 16 19
48 30 3
31 18 13
4 46 25
21 42 20
36 5 20
28 47 7
49 13 19
22 49 26
31 22 10
12 31 17
36 12 19
27 36 20
25 27 18
15 7 1
25 15 1
17 25 2
4 2 6
14 4 24
43 14 28
3 43 14
10 41 22
48 29 11
6 17 23
3...

output:

4873781248

result:

ok 1 number(s): "4873781248"

Test #24:

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

input:

50
6 5 11
31 7 23
31 4 11
17 40 27
48 17 6
11 27 5
25 1 4
16 18 27
15 41 0
16 6 4
38 16 3
50 14 10
13 25 10
39 42 14
31 39 1
11 12 7
34 11 25
20 47 6
8 23 14
45 38 13
21 45 16
34 30 6
8 20 8
15 22 15
34 46 8
37 8 0
28 37 26
50 28 27
43 50 1
2 43 5
21 2 28
31 21 18
3 31 20
19 3 18
29 19 24
49 29 19
1...

output:

6627000320

result:

ok 1 number(s): "6627000320"

Test #25:

score: 0
Accepted
time: 22ms
memory: 9624kb

input:

100000
77509 98467 20
62793 82930 13
78416 93950 22
68024 363 25
76602 26638 26
97411 46887 18
18793 21254 20
47826 41000 18
86390 80372 10
83578 11162 21
40816 93125 28
81656 29458 22
60803 10881 3
19917 3037 20
54529 49999 30
71885 88319 27
22640 31391 21
17531 86333 29
81083 26792 21
98931 94662 ...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #26:

score: 0
Accepted
time: 21ms
memory: 9576kb

input:

100000
61082 64274 26
2524 97936 15
33812 66610 11
63896 64837 3
30698 3579 11
81931 62604 16
19047 70162 16
36726 3057 13
64203 17364 16
69280 36985 16
3337 89788 13
88842 12813 18
16874 32296 20
49786 40743 6
90190 28728 18
83054 26036 3
20956 35543 12
80726 76814 26
18067 41832 29
29141 6466 1
11...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #27:

score: 0
Accepted
time: 22ms
memory: 9612kb

input:

100000
32065 6514 6
46298 22865 27
31782 1816 23
48244 78061 6
64707 94898 3
3312 77538 22
61439 66492 7
40836 6363 14
83264 96820 6
53392 32874 28
92991 33277 17
47423 88513 8
48226 32691 25
54978 4761 12
71753 2904 16
6533 7483 1
59861 6038 15
28646 88936 5
70621 85524 13
75585 7820 12
79874 19972...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #28:

score: 0
Accepted
time: 23ms
memory: 9544kb

input:

100000
77998 66665 28
24395 81209 13
12850 26840 24
73976 90222 4
83369 9122 11
46763 31616 1
57305 29011 19
77392 7281 29
77468 30220 15
26195 72102 28
32148 55808 16
76154 30307 14
80160 66485 10
50719 52552 17
23011 68774 19
81928 62632 9
42832 28860 13
4934 12595 22
3021 68846 6
77668 39000 4
71...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #29:

score: 0
Accepted
time: 21ms
memory: 9600kb

input:

100000
89285 98835 11
91665 31625 30
50863 60088 2
57244 91815 25
88430 87803 13
29256 18629 8
807 34515 17
13966 73503 2
82929 21804 18
37367 58483 0
94972 17602 22
85285 60559 1
66754 8031 4
70302 32847 12
76524 77739 5
66375 76088 9
4714 80344 0
52446 94366 12
63102 30170 30
40018 82086 5
33286 4...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #30:

score: 0
Accepted
time: 18ms
memory: 9616kb

input:

100000
20924 87015 2
14354 5682 30
82906 72512 23
34174 83045 28
68077 95852 21
94668 17055 5
8701 76866 4
50275 98048 6
48746 39217 18
75081 11880 6
55077 3968 26
76307 24676 30
36897 51076 1
16966 61832 24
73884 70080 5
1890 273 18
97903 3279 12
91165 14578 16
32864 55453 24
86482 41783 9
35908 46...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #31:

score: 0
Accepted
time: 22ms
memory: 9560kb

input:

100000
19022 18552 7
97237 98362 8
22364 65996 28
26669 84956 7
99883 15208 17
88294 19838 22
54637 30574 13
13265 88769 18
59697 41619 12
52639 95630 28
76662 21289 17
22996 77474 25
86372 39120 26
93943 67459 28
51436 13574 11
16171 36552 24
61640 67229 3
59860 62061 19
25325 12507 22
66175 13205 ...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #32:

score: 0
Accepted
time: 22ms
memory: 9548kb

input:

100000
3421 99506 13
82098 93053 19
95807 7383 15
96376 65184 29
92955 84318 12
44257 74060 23
18347 47285 8
94954 56564 4
74912 68573 18
44497 50305 16
43004 17531 21
20703 61229 3
80601 8818 20
12381 13087 29
96483 22999 7
98239 6806 9
99907 38376 22
80746 6940 15
3718 82171 1
90183 77016 19
28701...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #33:

score: 0
Accepted
time: 21ms
memory: 9620kb

input:

100000
1818 70751 22
96976 78246 6
68931 89225 17
84025 94430 14
1606 8180 4
58994 53936 4
47996 99549 14
97497 54905 13
42722 91192 16
74401 50398 16
28969 67421 27
39334 23898 4
74240 17132 19
35390 76510 5
83356 8974 7
31953 67031 22
63213 58399 16
99674 14104 28
5526 88200 5
46155 94030 2
81284 ...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #34:

score: 0
Accepted
time: 18ms
memory: 9548kb

input:

100000
46381 6060 5
1237 76876 14
1066 12675 6
69084 23926 4
78297 18181 10
96776 41218 17
22078 88951 15
90080 85741 24
64120 39958 9
61362 12007 1
65038 87281 25
35326 4732 9
68410 1905 23
3079 4788 5
66897 89357 3
56867 6540 18
78117 77250 29
95709 43499 6
76732 15950 16
71840 78858 9
45001 32973...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #35:

score: 0
Accepted
time: 22ms
memory: 9628kb

input:

100000
85844 42690 1
26753 2290 14
17013 27224 9
2976 70171 18
25564 22891 11
64888 12638 9
74880 71944 6
52120 75004 23
32669 67316 28
53503 95616 25
38723 17703 24
35910 82600 3
73793 73658 10
18355 31550 9
59036 62466 19
30869 14507 22
40990 16439 27
30789 46089 2
248 30840 0
12938 77688 10
51403...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #36:

score: 0
Accepted
time: 21ms
memory: 9636kb

input:

100000
36894 48899 0
81122 58714 10
49960 62803 2
14798 45655 27
15917 52516 18
22082 85512 27
73218 78040 30
88395 48056 18
23888 15501 17
59558 83836 10
7913 15122 4
78020 34867 11
29826 90714 7
64097 35907 11
97253 16197 21
52088 21844 18
30338 59411 16
55459 67297 10
46006 93939 26
36944 97096 1...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #37:

score: 0
Accepted
time: 18ms
memory: 9580kb

input:

100000
25219 6581 10
35247 32036 21
67544 37410 8
4576 59900 11
99766 22805 9
72947 6277 22
25340 58335 30
90562 79343 30
8946 43063 3
8611 33512 24
73260 67025 15
3228 83788 6
69634 58126 27
36924 86176 20
91184 99763 30
86612 25733 30
56632 88350 22
73113 69254 26
25423 16768 22
17710 11078 21
667...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #38:

score: 0
Accepted
time: 18ms
memory: 9556kb

input:

100000
91932 34024 12
27466 87049 4
71119 48759 5
63533 77044 27
75362 54960 28
75335 86605 20
67551 77076 2
42297 27391 13
36199 98063 21
86439 3874 27
45759 90481 28
68218 42603 4
28619 24301 19
22998 67653 13
73744 93996 30
8338 42529 16
54266 44367 11
43716 99442 23
87575 8299 7
21 2237 2
10731 ...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #39:

score: 0
Accepted
time: 23ms
memory: 9612kb

input:

100000
89001 50571 29
55285 80641 26
29006 66567 5
37089 75243 1
90566 32550 7
46122 45211 24
5109 27715 7
52388 58886 3
20119 43958 28
45002 73196 28
22202 7737 19
71324 77132 27
34440 50297 23
84842 61137 16
36655 94382 21
67879 91406 24
18291 22602 17
85163 65525 9
51915 87313 9
1016 38295 29
326...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #40:

score: 0
Accepted
time: 18ms
memory: 9548kb

input:

100000
96956 67654 1
78654 9018 22
65211 5996 21
83587 34913 9
83756 59024 23
80941 87322 22
70538 24973 6
80770 71496 20
46175 67087 4
91861 31370 15
83633 48211 1
45396 34781 4
75735 54757 23
38997 96555 30
71529 85618 0
63987 38245 9
13492 86786 13
32061 83004 24
96628 90525 6
43556 31643 3
62979...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #41:

score: 0
Accepted
time: 22ms
memory: 9628kb

input:

100000
69102 53801 14
60300 59825 30
53448 80345 21
64906 47001 0
17589 64073 3
94833 26595 1
52196 81641 18
16181 6354 3
47478 74820 16
77879 73638 6
47518 85819 19
26949 35683 2
12636 88440 23
68771 78725 20
661 11041 0
33374 24123 4
64065 78414 2
41725 44378 15
84700 77391 21
43823 64509 13
70282...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #42:

score: 0
Accepted
time: 18ms
memory: 9560kb

input:

100000
4128 68580 30
56782 68946 2
26400 16948 2
67672 59482 17
14780 83032 20
4768 81470 9
34630 30068 1
33893 58228 0
57458 84767 9
56401 59460 22
26220 29588 24
48106 82608 7
25927 62109 11
8247 59086 25
50080 89903 1
28865 56664 24
67397 57774 29
56101 4255 7
60598 95279 5
37659 85807 5
33248 94...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #43:

score: 0
Accepted
time: 18ms
memory: 9492kb

input:

100000
69535 4929 24
34291 47364 12
94251 76672 13
81164 74338 10
23859 88753 6
88248 40169 16
9152 46503 25
94292 20686 25
37744 32117 17
53082 59022 16
99604 49375 22
63852 49700 10
2063 91068 30
78550 67023 0
94188 76413 1
83945 33101 3
69768 44651 2
68354 36266 9
37098 5301 8
47789 41150 15
6003...

output:

107373108658176

result:

ok 1 number(s): "107373108658176"

Test #44:

score: 0
Accepted
time: 23ms
memory: 9524kb

input:

100000
2 1 10
3 1 24
4 2 2
5 4 19
6 2 2
7 1 26
8 1 15
9 2 29
10 7 20
11 3 29
12 8 12
13 11 1
14 3 29
15 3 12
16 5 6
17 8 12
18 8 15
19 4 15
20 13 25
21 7 11
22 13 1
23 12 10
24 1 15
25 5 29
26 1 7
27 23 29
28 16 2
29 14 23
30 26 6
31 14 27
32 14 26
33 29 7
34 26 5
35 18 2
36 12 14
37 30 5
38 29 4
39...

output:

73210133479424

result:

ok 1 number(s): "73210133479424"

Test #45:

score: 0
Accepted
time: 24ms
memory: 9524kb

input:

100000
2 1 14
3 1 21
4 3 19
5 1 16
6 1 0
7 6 11
8 7 23
9 4 12
10 2 28
11 9 6
12 6 17
13 1 28
14 2 9
15 1 8
16 10 1
17 13 4
18 4 20
19 8 28
20 11 18
21 18 0
22 8 26
23 21 15
24 9 22
25 11 16
26 11 0
27 14 24
28 16 23
29 13 18
30 10 23
31 30 17
32 13 18
33 25 5
34 19 2
35 17 6
36 28 12
37 21 9
38 37 1...

output:

69516461604864

result:

ok 1 number(s): "69516461604864"

Test #46:

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

input:

100000
2 1 28
3 1 0
4 1 5
5 1 23
6 1 25
7 3 25
8 4 25
9 3 13
10 3 1
11 1 8
12 3 8
13 6 17
14 8 11
15 8 9
16 2 13
17 4 18
18 10 20
19 5 27
20 8 22
21 6 5
22 9 25
23 2 21
24 1 28
25 2 13
26 21 5
27 26 0
28 10 0
29 1 3
30 3 3
31 7 16
32 6 8
33 11 9
34 24 26
35 14 13
36 18 25
37 7 1
38 35 22
39 26 26
40...

output:

74364942811136

result:

ok 1 number(s): "74364942811136"

Test #47:

score: 0
Accepted
time: 25ms
memory: 9280kb

input:

100000
2 1 11
3 1 0
4 3 4
5 1 29
6 5 5
7 6 1
8 7 26
9 6 26
10 9 29
11 9 4
12 1 28
13 1 5
14 13 3
15 14 13
16 1 12
17 16 3
18 7 9
19 18 25
20 1 14
21 20 5
22 7 17
23 22 21
24 23 9
25 11 30
26 16 28
27 26 9
28 1 12
29 28 21
30 29 20
31 1 22
32 31 16
33 32 21
34 1 7
35 34 1
36 1 0
37 1 25
38 36 29
39 3...

output:

43176517697536

result:

ok 1 number(s): "43176517697536"

Test #48:

score: 0
Accepted
time: 21ms
memory: 9300kb

input:

100000
2 1 7
3 2 4
4 2 18
5 4 19
6 5 20
7 6 16
8 7 17
9 8 5
10 9 15
11 10 12
12 11 27
13 12 4
14 1 21
15 14 5
16 15 1
17 1 12
18 17 8
19 6 18
20 14 10
21 20 1
22 1 13
23 22 12
24 23 0
25 1 27
26 1 16
27 26 30
28 1 5
29 28 0
30 29 13
31 1 0
32 31 17
33 32 15
34 33 18
35 1 18
36 35 19
37 11 0
38 37 28...

output:

43046762708992

result:

ok 1 number(s): "43046762708992"