QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#863832#8591. Shopseaten_book#7 100ms19464kbC++232.7kb2025-01-19 23:30:172025-01-19 23:30:17

Judging History

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

  • [2025-01-19 23:30:17]
  • 评测
  • 测评结果:7
  • 用时:100ms
  • 内存:19464kb
  • [2025-01-19 23:30:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define int ll
using ld = long double;
using pii = pair<int, int>;

#define S second
#define F first
#define mp make_pair
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#define mispertion ios_base::sync_with_stdio(0),cin.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()

const ld PI = 3.1415926535;
const ld eps = 1e-9;
const int N = 1e5 + 2;
const int M = 1.5e6 + 13;
ll mod = 998244353;
const int infi = 2e9;
const ll infl = 1e16;
const int P = 31;

int mult(int a, int b) {
    return a * 1LL * b % mod; }

int sum(int a, int b) {
    if(a + b >= mod)
        return a + b - mod;
    if(a + b < 0)
        return a + b + mod;
    return a + b;
}

ll binpow(ll a, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 1) {
        return binpow(a, n - 1) * a % (mod);
    } else {
        ll b = binpow(a, n / 2);
        return b * b % (mod);
    }
}

struct dsu{
    int p[N], sz[N], cnt;

    void init(int n){
        for(int i = 1; i <= n; i++)
            p[i] = i;
        for(int i = 1; i <= n; i++)
            sz[i] = 1;
        cnt = n;
    }

    int getp(int v){
        if(p[v] == v)
            return v;
        return p[v] = getp(p[v]);
    }

    void uni(int a, int b){
        a = getp(a);
        b = getp(b);
        if(a == b)
            return;
        if(sz[a] > sz[b])
            swap(a, b);
        if(sz[a] == 1)
            cnt--;
        if(sz[b] == 1)
            cnt--;
        p[a] = b;
        sz[b] += sz[a];
    }
};

int n, m, c[N], used[N];
vector<int> g[N];

void dfs(int v, int col){
    used[v] = 1;
    c[v] = col;
    for(auto u : g[v])
        if(!used[u])
            dfs(u, col ^ 1);
}

inline void solve() { 
    cin >> n >> m;
    vector<pair<int, pii>> vec = {};
    for(int i = 0; i < m; i++){
        int u, v, w;
        cin >> u >> v >> w;
        vec.push_back({w, {u, v}});
    }
    int ans;
    sort(all(vec));
    dsu ds;
    ds.init(n);
    for(auto e : vec){
        int u = e.S.F, v = e.S.S;
        int w = e.F;
        if(ds.getp(u) == ds.getp(v))
            continue;
        g[v].push_back(u);
        g[u].push_back(v);
        ds.uni(u, v);
        if(ds.cnt == 0){
            ans = w;
            break;
        }
    }
    cout << ans << '\n';
    for(int i = 1; i <= n; i++){
        if(!used[i])
            dfs(i, 0);
        cout << (c[i] ? 'B' : 'D');
    }
    cout << '\n';
}

signed main() {
    mispertion;
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i ++){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 7
Accepted

Test #1:

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

input:

3 3
1 2 3
2 3 1
1 3 2

output:

2
DDB

result:

ok inconveniences = 2

Test #2:

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

input:

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

output:

9
DDBBD

result:

ok inconveniences = 9

Test #3:

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

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
DDBBDBBB

result:

ok inconveniences = 19258

Test #4:

score: 7
Accepted
time: 52ms
memory: 19464kb

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
DBDDDBBBDDBBD

result:

ok inconveniences = 65982

Test #5:

score: 7
Accepted
time: 67ms
memory: 19280kb

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
DB

result:

ok inconveniences = 509

Test #6:

score: 7
Accepted
time: 59ms
memory: 19452kb

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
DBDDBBDBBDDBDBB

result:

ok inconveniences = 83506

Test #7:

score: 7
Accepted
time: 99ms
memory: 19412kb

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
DDBDBDBBBDBDDDDB

result:

ok inconveniences = 22372

Test #8:

score: 7
Accepted
time: 100ms
memory: 19280kb

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
DBDBDDDDDBDDBBBB

result:

ok inconveniences = 38343

Test #9:

score: 7
Accepted
time: 16ms
memory: 8588kb

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
DBDDBDBDDDBBBBBB

result:

ok inconveniences = 309636

Test #10:

score: 7
Accepted
time: 11ms
memory: 6488kb

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:

187454
DBBDDDBBDDBDDBDB

result:

ok inconveniences = 187454

Subtask #2:

score: 0
Runtime Error

Test #11:

score: 0
Runtime Error

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:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Runtime Error

Test #31:

score: 0
Runtime Error

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:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%