QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#407563#8591. Shopsucup-team00424 305ms64444kbC++202.0kb2024-05-08 23:53:132024-05-08 23:53:13

Judging History

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

  • [2024-05-08 23:53:13]
  • 评测
  • 测评结果:24
  • 用时:305ms
  • 内存:64444kb
  • [2024-05-08 23:53:13]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
struct DSU {
    std::vector<int> f, siz;
    
    DSU() {}
    DSU(int n) {
        init(n);
    }
    
    void init(int n) {
        f.resize(n);
        std::iota(f.begin(), f.end(), 0);
        siz.assign(n, 1);
    }
    
    int find(int x) {
        while (x != f[x]) {
            x = f[x] = f[f[x]];
        }
        return x;
    }
    
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    
    bool merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        }
        siz[x] += siz[y];
        f[y] = x;
        return true;
    }
    
    int size(int x) {
        return siz[find(x)];
    }
};
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, m;
    std::cin >> n >> m;
    
    std::vector<int> u(m), v(m), w(m);
    for (int i = 0; i < m; i++) {
        std::cin >> u[i] >> v[i] >> w[i];
        u[i]--;
        v[i]--;
    }
    
    std::vector<int> p(m);
    std::iota(p.begin(), p.end(), 0);
    std::sort(p.begin(), p.end(),
        [&](int i, int j) {
            return w[i] < w[j];
        });
    
    DSU dsu(n);
    int ans = 0;
    std::vector<int> deg(n);
    std::vector<std::vector<int>> adj(n);
    for (auto i : p) {
        if (dsu.merge(u[i], v[i])) {
            if (deg[u[i]]++ == 0 || deg[v[i]]++ == 0) {
                ans = w[i];
            }
            adj[u[i]].push_back(v[i]);
            adj[v[i]].push_back(u[i]);
        }
    }
    
    std::cout << ans << "\n";
    std::vector<int> d(n);
    auto dfs = [&](auto &&self, int x, int p) -> void {
        for (auto y : adj[x]) {
            if (y == p) {
                continue;
            }
            d[y] = d[x] ^ 1;
            self(self, y, x);
        }
    };
    dfs(dfs, 0, -1);
    
    for (int i = 0; i < n; i++) {
        std::cout << "BD"[d[i]];
    }
    std::cout << "\n";
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

3 3
1 2 3
2 3 1
1 3 2

output:

2
BBD

result:

ok inconveniences = 2

Test #2:

score: 7
Accepted
time: 1ms
memory: 3584kb

input:

5 6
3 2 3
4 2 1
5 3 9
1 3 5
1 4 2
2 3 1

output:

9
BBDDB

result:

ok inconveniences = 9

Test #3:

score: 7
Accepted
time: 24ms
memory: 5244kb

input:

8 135737
1 4 763713071
3 7 45141437
4 8 618418466
6 8 91803956
7 5 972595945
5 2 751163228
2 8 9886315
4 3 106470622
8 6 949495949
1 2 885918825
4 6 322040168
7 6 754489330
4 8 618968328
5 3 996860159
3 6 210132897
3 4 591744987
8 7 447985622
2 4 4833956
5 7 610154418
2 5 410116873
2 5 912717336
8 7...

output:

19258
BBDDBDDD

result:

ok inconveniences = 19258

Test #4:

score: 7
Accepted
time: 55ms
memory: 7276kb

input:

13 265680
1 4 380374649
3 10 784226975
4 11 872278132
5 11 592626606
6 11 526829741
9 11 740573742
10 8 276205430
8 12 63494864
11 2 71771791
2 13 737308410
12 7 878733769
7 13 903269395
5 9 120579034
5 12 138606132
4 11 662866874
11 2 700788392
6 10 585492424
5 12 28226068
13 10 114889571
7 11 2004...

output:

65982
BDBBBDDDBBDDB

result:

ok inconveniences = 65982

Test #5:

score: 7
Accepted
time: 74ms
memory: 8908kb

input:

2 373114
1 2 974989916
1 2 167686461
2 1 874714837
1 2 864433403
2 1 5005374
2 1 395259584
2 1 508862785
2 1 44724432
2 1 454094822
1 2 508318735
1 2 977605453
1 2 265311692
1 2 773880917
2 1 586327430
1 2 768708534
2 1 100847253
1 2 6244686
1 2 323240784
2 1 45647197
1 2 914752947
1 2 222102030
1 2...

output:

509
BD

result:

ok inconveniences = 509

Test #6:

score: 7
Accepted
time: 57ms
memory: 7772kb

input:

15 293068
1 4 258818839
4 3 204793003
5 3 854744190
3 9 788200755
9 7 108614733
11 10 503890749
12 10 734694989
10 2 350766061
2 6 597468181
6 8 227104490
8 7 345420481
7 13 180194608
14 13 674888672
13 15 167655205
6 3 855543442
3 9 687174916
15 6 641812755
4 11 353729428
11 9 32193849
11 1 1354442...

output:

83506
BDBBDDBDDBBDBDD

result:

ok inconveniences = 83506

Test #7:

score: 7
Accepted
time: 108ms
memory: 10980kb

input:

16 500000
1 8 62757308
4 3 6086405
8 13 122144601
9 3 64557726
3 11 812380590
11 5 453430162
12 10 361214682
10 5 261815175
14 2 515797344
2 7 642876852
7 5 35056850
5 6 743310007
6 15 282260939
15 13 94433700
13 16 448013089
16 11 719836976
16 12 719865713
9 6 408172771
5 11 723450797
7 13 76614544...

output:

22372
BBDBDBDDDBDBBBBD

result:

ok inconveniences = 22372

Test #8:

score: 7
Accepted
time: 112ms
memory: 10952kb

input:

16 500000
3 8 707927663
5 6 31687997
7 14 697861063
9 4 347120998
10 2 664365468
12 15 99754727
14 8 883245817
8 1 659078917
1 6 345106180
6 11 869578009
15 4 870015619
4 13 686672311
13 2 234049952
2 11 896975378
11 16 972960752
15 1 584513015
3 1 303056953
16 9 472827775
8 16 653700355
15 16 36838...

output:

38343
BDBDBBBBBDBBDDDD

result:

ok inconveniences = 38343

Test #9:

score: 7
Accepted
time: 17ms
memory: 4432kb

input:

16 77010
1 2 793736027
2 12 72260632
8 9 402732232
9 3 256827318
3 4 437695398
10 5 265719081
5 6 618443602
12 11 40956038
11 4 852273728
4 6 853314294
13 7 658974087
7 6 798496221
6 15 978830498
15 14 443477053
14 16 550578548
12 5 361355178
11 2 762353204
15 4 601752138
7 11 160395331
15 13 220004...

output:

309636
BDBBDBDBBBDDDDDD

result:

ok inconveniences = 309636

Test #10:

score: 0
Wrong Answer
time: 10ms
memory: 4112kb

input:

16 64382
4 13 443239253
5 1 990800886
1 3 966518884
9 11 718720038
10 11 795048977
11 6 127421564
6 7 944954312
7 2 797353656
2 8 486371900
14 12 679402638
12 3 852829651
3 8 288307369
8 16 878703936
15 13 797175282
13 16 689574513
1 12 842120755
4 13 320340401
1 15 174145088
6 15 888245466
13 4 938...

output:

188987
BDDDBBDDBBDBBDBB

result:

wrong answer your claimed answer is 188987, but the inconveniences of your plan is actually 187454

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 305ms
memory: 64444kb

input:

500000 499999
1 2 776715136
2 3 406881694
3 4 265792290
4 5 507607272
5 6 182246639
6 7 997847597
7 8 164130256
8 9 278962226
9 10 411194641
10 11 363646402
11 12 672225656
12 13 494629089
13 14 717664153
14 15 121619271
15 16 476857704
16 17 301215244
17 18 810217743
18 19 850722975
19 20 10710274
...

output:

999999116
BDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBD...

result:

wrong answer your claimed answer is 999999116, but the inconveniences of your plan is actually 998789691

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 24
Accepted

Test #31:

score: 24
Accepted
time: 153ms
memory: 35276kb

input:

366489 397001
2 127909 1
7 171229 1
8 158597 1
11 282213 1
14 356007 1
15 286102 1
16 93205 1
17 260111 1
18 138962 1
20 359938 1
29 223905 1
31 357684 1
32 259968 1
34 65205 1
37 200276 1
41 83195 1
43 159858 1
48 332277 1
50 320322 1
51 338467 1
53 262785 1
55 83815 1
56 173198 1
58 169473 1
63 19...

output:

1
BDDDBDDBBDDBDDBDDBDDDDBBBBDDDDDDDBDDDBBDBBDDBBDDDBDDBBDDDDDBBDDBDDBDBBDDDDDBBBBBDBBBDDDBBBDDBDDBBBDBBDBBDDDDBDBDBBBDDDDBBDDBBDBBDBBBDDBDBDBBDBDBBBBDDBBBBBDBBDBDDBBBBBDBDDDBDDDDDDBDDBBDBDDDBBDDDDBDDDBDBBBDBDBDDBBBBBDBBBBBDDDBDBBBDBBBBDDBBDBBBDDDDDDBBDBBBDDBBBDBDBDBBBDDBBDBDBBDBBDBDDBBDDBDDDBDBDBBDD...

result:

ok inconveniences = 1

Test #32:

score: 24
Accepted
time: 194ms
memory: 44540kb

input:

475552 488952
2 161263 1
3 312211 1
5 41910 1
6 421865 1
7 340911 1
9 419906 1
10 468773 1
13 17837 1
18 465833 1
19 297766 1
21 234125 1
26 218984 1
28 296050 1
29 411520 1
30 38207 1
33 370786 1
34 21620 1
35 467168 1
40 136766 1
42 353240 1
44 194443 1
46 119022 1
48 23233 1
54 380603 1
60 99339 ...

output:

1
BBBBBBBDBDDBDBDBBDBBDBBDBDBBBBDBBBBDDDBBBDBDBBBBBDBDBDBBBBBBDBDDDBDDDBBBBDBDBDDDDBDDBBDBDDDDDBBDBDBDBBBDBBDDBBDDDDDDBDDBDBBDBBDBDDBBDDDDDDBDDDDBBBBDDDBDDDBDDDDBDBDBDDBDDDDDDBBDDDBBBDBBDDDBBBBBBBBDDDDDDBDBDDBDDDDBBDDBDBDBBDBBBBBDDDBBDBDBBDBBBBDDDDBDDDDBBBDDDBBDDDBBDDBDBBDBBBDDDDBBBBDDDBDBDBBBDBDDDD...

result:

ok inconveniences = 1

Test #33:

score: 24
Accepted
time: 40ms
memory: 14504kb

input:

128817 140020
2 53427 1
5 86824 1
6 33490 1
11 63864 1
14 109608 1
15 12909 1
16 45790 1
19 27271 1
22 54044 1
24 11063 1
32 53692 1
35 70034 1
38 84224 1
39 64068 1
43 72895 1
44 51948 1
45 40428 1
49 127824 1
50 52852 1
60 25795 1
61 105666 1
65 41013 1
67 97450 1
69 49349 1
71 47569 1
72 70751 1
...

output:

1
BBDBDDDBDDBDBBDBDBDDDBBDBDBDBBDDBDBBBDDDDDBDDDBBDDDBDDDDDDBBBBBBBDBDBBDBBBBBDBDDDBDDDDDBBDDDDBBDDDDBDDDBBBBBDBDBDDDBBDBBDBBDDDDDDBBBDDBBBBDBDBBBBDBDDDDBDDDDDBBDBBBDDBDDDBDBDDBDDDDDBDBDDBBBDBDBDDBBDBBDBDBDDBDDDDBBDBBBDBBDDDDBBDBDDDBBDBDDDDBBBDDBDBBBBBBBDBDBBDBBBBDDDDBDBDBDBDBDBBDBDDDDDBDDBBDBDBDDBD...

result:

ok inconveniences = 1

Test #34:

score: 24
Accepted
time: 117ms
memory: 29492kb

input:

299635 331829
5 197808 1
11 67054 1
12 84275 1
15 287112 1
16 274955 1
24 40825 1
30 266299 1
34 81379 1
35 99815 1
38 219853 1
42 189961 1
47 107895 1
48 137516 1
50 80614 1
54 264232 1
55 93625 1
62 143056 1
63 70844 1
64 72811 1
65 164091 1
68 248158 1
70 9821 1
72 156352 1
77 215022 1
81 270025 ...

output:

1
BDDBBDBBDDDBDBDDBDBBDBDBBBDDBDDDDDBBBDBDBDDBBDBDDBDDBDDBDDDBDDBDDDDBDBBDDBBBBBDBBDDDBBBBDDBBBDDBDBDBDBBDBBDBBBDDDDDDBDDDBBBDBBBBDBDBDBBBBBBBBDBBBDBDBDBDBDDDBDBBBDBBBBBBBBDDDBDDBBBBBBDBBBBDDDDBBBDDDDDDDBDDDDBDDDBBDDDBDBDDDDBBDDDBBBBDBBDDDDDDDBDDDBDBDBDBDBBDBBBBDBBBBBDBDDBBDDDDDBDBBBDDBBBDDBBBBBDDBB...

result:

ok inconveniences = 1

Test #35:

score: 24
Accepted
time: 154ms
memory: 36348kb

input:

369927 447544
1 150509 1
5 250257 1
6 149327 1
7 201307 1
15 330381 1
16 158914 1
18 99391 1
24 90164 1
25 199087 1
28 306199 1
32 83429 1
35 212184 1
36 29977 1
37 261629 1
44 99341 1
45 48378 1
51 130523 1
53 148929 1
58 77382 1
71 211093 1
72 305907 1
73 227420 1
75 188876 1
76 71437 1
79 354402 ...

output:

1
BDDDBBBDDDDBBDDBDDDBDDBDBDDDDDDDBDBDDBBBBDBBBDDBDDDBDBBDBBBDDBBBBBDBBDBBDBDDDDDDBBDBBDDDBDDBBDDDDDDBDBDBBDBBDDDDBDBDBBDDBDDBBDDDBBBBDDBBBDBBBBBBDDDBBDDDBBBBBDDBDDBBDDBDBDBBBBBDDBDBBBBBBBDBDBBBDDBDBBDDBBBBDDDBDBBBBDDBBDBBBBDDDDBBDBDBDDDBDBBDBBDDBBBDDBDDDBDBDDBBDBBDBDBDBBDDDDBBBBDDDDBBDDDBBBDBBDBBDD...

result:

ok inconveniences = 1

Test #36:

score: 24
Accepted
time: 192ms
memory: 46520kb

input:

500000 500000
4 319400 1
12 186157 1
13 443669 1
15 227339 1
19 101284 1
20 183604 1
23 273179 1
26 236933 1
27 79090 1
28 826 1
29 7574 1
31 370188 1
32 48463 1
34 113530 1
35 209157 1
46 13739 1
47 188127 1
48 97203 1
51 251724 1
52 469749 1
53 451782 1
56 249224 1
58 262324 1
60 380990 1
61 82320...

output:

1
BBBBDBBDDBDBBBBDBBDBBDDDBBBDDBBDDDDDDDBBDBBBDDDBDBBDBBBDBBBBBBBDDDBDBBBBBDDDDDDBDDBDDBBDDBDDBBDBBBDBDDBBBBBDBBBBDDDBDDDDBBBDDBBBBBDBDDDDBBDBBBDBBDDDDBDDBDDBDDBBDDDBDBDBBBBDDBDDDDBBDBBBBBBBDDDBBBDBDBBBBBDDDBBDBDBDDDDBBBDBDDBDDDDDBBDDDDBDDDBDBBBDDBBDBBDBBBDBDBDBBDDBBDDDBDDBDDBDBDDBDDDDDBDDBBDBDDBDBD...

result:

ok inconveniences = 1

Test #37:

score: 24
Accepted
time: 185ms
memory: 46336kb

input:

500000 500000
2 182927 1
5 313016 1
9 438269 1
10 97892 1
11 373266 1
13 314494 1
14 318813 1
20 102513 1
23 304478 1
24 162451 1
27 207273 1
30 182950 1
34 133161 1
35 62401 1
37 102023 1
38 19183 1
41 96619 1
42 264471 1
45 339682 1
46 60188 1
51 134306 1
53 85702 1
54 170539 1
55 74017 1
73 14900...

output:

1
BDDDBDBDBBDBBBDBDBBDDBBBBBBBDBDDBDDDBDBDBDBBBBDDBBDDBBBBDBBBDDDDBBDBDBDBBDBBDDBDDDBDBBBDDBDBDBBBDDDDDDDDDDBDDDBDBBBDBBDDBBBDBBBDDDBBDBBDDDDDBBBDDDBDDBBDDDBDDBBDDDBBDBDDDDDBBDDBBDDDDBBBDBDBBDBDBBDBDBDBDDBDBBDDBDBDDDDDBDBDDDBBBDDBDBBBBDBBDDBDBBBBDBBBBDBBDDBDDDDDBDDBBBBDBDBBDBDBDBBBDDBDDDDDDBBDBDBDDD...

result:

ok inconveniences = 1

Test #38:

score: 24
Accepted
time: 211ms
memory: 46488kb

input:

500000 500000
4 490349 1
5 377743 1
7 261998 1
14 410844 1
17 106150 1
20 477772 1
22 48037 1
24 388329 1
26 328805 1
28 248860 1
30 216330 1
34 479575 1
37 303722 1
38 392533 1
40 191119 1
42 177919 1
44 322555 1
45 306160 1
50 129452 1
51 215260 1
53 146880 1
56 441549 1
64 249852 1
69 422318 1
70...

output:

1
BDDDBDBDDBBDDDBDDDBDDBBBDBDDBBDBBDBBDBBDDBBBDDBBDDBBBBDDBBDBDDBDDBDBDDDDBBBDDDBDBBDDBDBBDDBDDBBDBDDBDDDBBBDBBDDDBDBBBDDBBBDBDBDDBBDDDDBBDBBBBBDDDDBBBDBDDBBDBBBDDDBDBBBDDDDDDDBDBBBBDBDBBBBBBDBDDBDBBBBDBDDDBDBBDDBDDBBBBDDDDDDBDBBBDDBBDBBDBDDDBBDBBBDBBDDBDBBBDDBDDBBBBDDDDDBDDBDBBDBDDDBDDDDDDDDDBDBDDB...

result:

ok inconveniences = 1

Test #39:

score: 24
Accepted
time: 187ms
memory: 46380kb

input:

500000 500000
9 213713 1
13 307012 1
14 327287 1
16 103990 1
23 409412 1
24 80587 1
25 91210 1
26 413674 1
28 167751 1
29 223056 1
31 395367 1
34 70127 1
38 344870 1
39 499865 1
40 91257 1
41 443805 1
43 109678 1
47 387825 1
49 328529 1
53 186674 1
59 197682 1
60 27560 1
61 402852 1
64 380750 1
66 1...

output:

1
BDDDDBBDDDBBDBBDDBBDDDDBDBBBBDBDBBBBDBDBBBDBDBBDDBDDBDBBDBDBBDDBDDDDDBDBDBDBBBBDBDDDBBDDBBBDDBDBBDDDDDBDDBBDDBBDDDDBDDBDBBDBDDBDDBBDDBBBBBDBDBBDBBDBBBDDBDBBBBDDDBDDDDBDDDBBDBDDBBDDDDDBDBDDDDDBBDBDDBBDDDDBBDDDDDDDDDBBBBBBDBDDDBDBBDBDDBBBBBBBBDBBDBBBDDDBDDDBDDDBBBBBBBDBDBBBDDDBBDBDDDDBDBDDDDBDDDBDBD...

result:

ok inconveniences = 1

Test #40:

score: 24
Accepted
time: 200ms
memory: 46444kb

input:

500000 500000
1 420147 1
2 70976 1
5 354943 1
6 261427 1
9 317379 1
11 31032 1
15 419781 1
16 155356 1
19 459807 1
25 72438 1
28 385731 1
30 19123 1
34 18208 1
35 332853 1
39 338723 1
41 356728 1
42 114047 1
44 389270 1
47 112208 1
48 23788 1
52 312381 1
57 317756 1
60 311741 1
61 218196 1
62 182171...

output:

1
BDDBDDDDDDBDBDBBBDDDBBDBBBDDBDDBDDBDDBBBDDBDDBDBDBDDBBBBDDBBDDDDDBDDDDBDDDBDDBBBBDDBDBDDDDBBBBBBBBBDBBDBBDBBBBDBDBDBDDBBBBDBBBDBDBDDDDDBBDDBBDBDDDBBBBBBDBDDDBBDBDBBBDBDBDDDDBDDDDBBBBBBBBBBBBBBBBBDBBDDDDDDDDDBBBDBBDDBBBDDBDBDBDBBBBDBDDBBBDBDDDBDBBBBDBBDBBDBBDDBBBDDBBDDDBBDBBDDDBBBBDBDBBBDDDBBDDDDBB...

result:

ok inconveniences = 1

Subtask #5:

score: 0
Skipped

Dependency #1:

0%