UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214523#2709. Maximum WeightThySecret301807ms3120kbC++111.9kb2024-11-19 20:21:132024-11-19 23:01:41

answer

#include <bits/stdc++.h>

using namespace std;

// #define int long long
// #define x first
// #define y second
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)

inline void debug() { cerr << '\n'; }
template<typename Type, typename... Other>
inline void debug(const Type& x, const Other&... y) { cerr << x << ' '; debug(y...); }
#define DEBUG(a...) cerr << "[" << #a << "] = ", debug(a);

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = N << 1;
const int INF = 0x3f3f3f3f;

template<typename Type>
inline void read(Type &res)
{
    res = 0;
    int ch = getchar(), flag = 0;
    while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
    while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
    res = flag ? -res : res;
}
template<typename Type, typename... Other>
inline void read(Type &res, Other&... y) { read(res), read(y...); }

int n, m, ans;
// int h[N], e[M], ne[M], w[M], idx;
array<int, 3> edge[N];
int pre[N], sz[N];

// inline void add(int a, int b, int c) { e[++ idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx; }

int rt(int x) { return pre[x] == x ? x : pre[x] = rt(pre[x]); }

void solve()
{
    iota(pre, pre + N, 0), fill(sz, sz + N, 1);
    // memset(h, -1, sizeof h), idx = -1, ans = 0;
    ans = 0;

    read(n, m);
    for (int i = 1; i <= m; i ++)
        read(edge[i][0], edge[i][1], edge[i][2]);
    sort(edge + 1, edge + 1 + m, [](const array<int, 3> &a, const array<int, 3> &b) { return a[2] < b[2]; });

    for (int i = 1; i <= m; i ++)
    {
        int u = edge[i][0], v = edge[i][1], w = edge[i][2];
        int fx = rt(u), fy = rt(v);
        if (fx == fy) continue;

        ans += sz[fx] * sz[fy] * w;

        pre[fx] = fy, sz[fy] += sz[fx];
        // add(u, v, w), add(v, u, w);
    }
    cout << ans << '\n';
}

signed main()
{
    int T; read(T);
    while (T --) solve();
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

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

input:

5
200 200
87 21 609
97 9 566
169 28 893
181 137 280
139 67 622
78 186 503
104 59 24
58 7 460
2 5 972...

output:

16352732
16336938
18311542
17074338
17304585

result:

ok 5 lines

Test #2:

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

input:

5
200 200
138 19 453
178 159 227
89 99 937
38 60 806
145 45 448
169 146 982
180 153 382
73 167 608
1...

output:

17101828
17550376
16746021
17786837
16222316

result:

ok 5 lines

Test #3:

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

input:

5
200 200
140 37 428
167 191 722
18 70 854
12 63 869
40 107 253
146 21 701
198 126 594
55 183 67
2 4...

output:

16466132
16907763
17447896
17281330
17606236

result:

ok 5 lines

Test #4:

score: 5
Accepted
time: 3ms
memory: 1964kb

input:

5
200 200
187 173 189
59 103 160
12 143 13
16 115 179
130 108 854
7 39 124
164 72 407
66 200 625
105...

output:

16551712
17073788
18382571
16125810
17394218

result:

ok 5 lines

Test #5:

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

input:

5
200 200
29 8 307
152 26 149
114 137 559
9 146 81
179 5 203
3 150 8
26 81 660
82 69 356
60 51 591
1...

output:

17720164
16949531
17616778
17620129
16288612

result:

ok 5 lines

Test #6:

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

input:

5
200 200
35 144 182
145 194 241
163 140 918
102 193 228
167 130 338
40 65 646
22 1 238
131 120 122
...

output:

17829792
17475817
17019069
17199330
17653988

result:

ok 5 lines

Test #7:

score: 0
Wrong Answer
time: 157ms
memory: 3120kb

input:

5
53735 100000
39892 35843 390
26908 36823 655
6371 23805 896
22798 20233 34
26039 37466 620
22807 2...

output:

-1895102282
1791391508
327228040
202560928
670981023

result:

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

Test #8:

score: 0
Wrong Answer
time: 148ms
memory: 3116kb

input:

5
10229 100000
7299 6840 113
6306 8765 160
5192 8138 791
6357 5200 186
9344 6620 230
2728 5157 294
1...

output:

1109829911
-1122107823
1755780455
323585334
273615662

result:

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

Test #9:

score: 0
Wrong Answer
time: 157ms
memory: 3120kb

input:

5
57846 100000
40438 9781 106
35677 46516 444
39104 10920 598
14172 5965 925
10993 42212 964
34922 5...

output:

-2099314784
1547436527
1413377354
581241738
1151909454

result:

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

Test #10:

score: 0
Wrong Answer
time: 166ms
memory: 3120kb

input:

5
83866 100000
54676 45243 758
42970 31099 721
27422 62458 4
64200 18592 974
7505 20672 900
83354 49...

output:

1287243825
-955501617
1570881617
52834253
-2059805057

result:

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

Test #11:

score: 0
Wrong Answer
time: 171ms
memory: 3116kb

input:

5
10818 100000
6480 6451 261
10486 2548 495
8142 9400 330
4568 1781 682
8289 5945 660
1058 5902 378
...

output:

2100073086
-1756388787
65222182
885196831
1304923918

result:

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

Test #12:

score: 0
Wrong Answer
time: 155ms
memory: 3120kb

input:

5
28267 100000
6205 10002 70
12719 28165 6
6174 15544 940
3052 1398 62
648 16984 103
17068 3616 397
...

output:

565936396
-141989645
1217754277
1114199411
1019190930

result:

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

Test #13:

score: 0
Wrong Answer
time: 111ms
memory: 3120kb

input:

5
33283 100000
134 21400 430
22159 6741 87
2473 18253 422
13630 28077 144
22002 24779 437
13034 2417...

output:

1376292552
1904441289
1295030791
401280754
-1608720914

result:

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

Test #14:

score: 0
Wrong Answer
time: 117ms
memory: 3120kb

input:

5
95017 100000
37418 35411 167
6415 94231 616
3744 60077 591
73070 5537 37
50016 18446 825
55281 519...

output:

-956839227
-118802518
-114499959
1556267020
909291755

result:

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

Test #15:

score: 0
Wrong Answer
time: 103ms
memory: 3120kb

input:

5
35374 100000
7390 8869 566
34086 23636 990
32887 4674 494
6452 18007 424
12723 34687 25
11020 3193...

output:

-1507360610
1180403601
-971337657
1695269274
-1053650527

result:

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

Test #16:

score: 0
Wrong Answer
time: 108ms
memory: 3116kb

input:

5
99901 100000
35090 96613 813
67573 26667 941
3022 45474 629
10290 52654 196
12701 59286 893
80077 ...

output:

647512826
607120396
673444632
-2051534667
-188678142

result:

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

Test #17:

score: 0
Wrong Answer
time: 109ms
memory: 3120kb

input:

5
60029 100000
51021 51437 658
17839 25439 501
51521 1893 516
20462 309 128
58519 8607 623
34157 498...

output:

-1580916113
-732670658
162131849
1565906928
-99085082

result:

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

Test #18:

score: 0
Wrong Answer
time: 109ms
memory: 3120kb

input:

5
25779 100000
2274 4201 54
11775 9137 148
697 21064 449
14126 25608 840
5579 19585 779
9641 15433 5...

output:

-767079017
-1735916503
-1748151711
670309655
-177308389

result:

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

Test #19:

score: 0
Wrong Answer
time: 95ms
memory: 3120kb

input:

5
33220 100000
31269 1383 683
18955 25297 299
700 12197 974
27221 20329 796
29285 29654 414
21164 21...

output:

-482493181
-2090433674
-1658802916
-452128752
-88449934

result:

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

Test #20:

score: 0
Wrong Answer
time: 98ms
memory: 3120kb

input:

5
17719 100000
11733 10279 4
15938 11631 578
9235 13763 91
13846 2450 912
12426 13022 236
13098 1628...

output:

2063540122
-847790555
661836246
-683196229
839479823

result:

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