QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#374078#7871. 命运zyc0704190 113ms9156kbC++141.8kb2024-04-02 11:32:162024-04-02 11:32:18

Judging History

This is the latest submission verdict.

  • [2024-04-02 11:32:18]
  • Judged
  • Verdict: 0
  • Time: 113ms
  • Memory: 9156kb
  • [2024-04-02 11:32:16]
  • Submitted

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e4 + 30;
const int M = 5e5 + 3;

struct node {
    int x, y, val, opt;
}e[M];
int n, m, ans, k, num, fa[N], s, mem, Pa[N];

bool cmp(node a, node b) {
    if(a.val == b.val) return a.opt < b.opt;
    return a.val < b.val;
}

int getfa(int x) {
    if(fa[x] == x) return x;
    return fa[x] = getfa(fa[x]);
}

bool check(int mid) {
    num = ans = 0;
    int tot = 0, x, y, fx, fy;
    for(int i = 1; i <= m; ++i)
        if(e[i].opt == 0) e[i].val += mid;
    sort(e + 1, e + 1 + m, cmp);
    for(int i = 1; i <= n; ++i) fa[i] = i;
    for(int i = 1; i <= m; ++i) {
        x = e[i].x; y = e[i].y;
        fx = getfa(x); fy = getfa(y);
        if(fx == fy) continue;
        ans += e[i].val; fa[fx] = fy;
        if(e[i].opt == 0) num++;
        tot++;
        if(tot == n - 1) break;
    }
    for(int i = 1; i <= m; ++i)
        if(e[i].opt == 0) e[i].val -= mid;
    return num >= k;
}

inline int getpa(int x) {return x == Pa[x] ? x : Pa[x] = getpa(Pa[x]);}

signed main() {
    int x, y, z, opt, pos;
    scanf("%lld%lld%lld%lld", &n, &m, &k, &s);
    for (int i = 1; i <= n; ++i) Pa[i] = i;
    for(int i = 1; i <= m; ++i) {
        scanf("%lld%lld%lld", &x, &y, &z);
        Pa[getpa(x)] = getpa(y);
        if (x == s || y == s) opt = 0, mem++;
        else opt = 1;
        e[i] = {x, y, z, opt};
    }
    for (int i = 1; i <= n; ++i)
    	if (getpa(i) != getpa(1)) return puts("nonnondayo"), 0;
    if (mem < k) return puts("nonnondayo"), 0;
    int l = -2e9, r = 2e9, mid;
    while(l <= r) {
        mid = (l + r) >> 1;
        if(check(mid)) l = mid + 1, pos = mid;
        else r = mid - 1;
    }
    check(pos);
    printf("%lld\n", ans - k * pos);
    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 78ms
memory: 7856kb

input:

49277 49276 1 49277
1 2 2000
2 3 3000
2 4 4000
3 5 5000
3 6 6000
4 7 7000
1 8 8000
7 9 9000
1 10 10000
5 11 11000
4 12 12000
3 13 13000
13 14 14000
1 15 15000
7 16 16000
11 17 17000
2 18 18000
10 19 19000
6 20 20000
4 21 21000
17 22 22000
1 23 23000
14 24 24000
4 25 25000
16 26 26000
15 27 27000
9 2...

output:

1214136002000

result:

ok single line: '1214136002000'

Test #2:

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

input:

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

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #3:

score: -5
Wrong Answer
time: 86ms
memory: 7732kb

input:

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

output:

23221341175

result:

wrong answer 1st lines differ - expected: 'nonnondayo', found: '23221341175'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 10
Accepted
time: 1ms
memory: 3616kb

input:

21 20 2 21
1 2 18581
1 3 9620
2 4 4362
1 5 7702
5 6 17435
4 7 11679
3 8 14832
1 9 15073
2 10 6595
5 11 19676
11 12 16943
12 13 5268
5 14 20262
8 15 8192
7 16 12340
7 17 1437
7 18 3064
2 19 10437
12 20 2882
19 21 13483

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #6:

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

input:

10 20 4 3
1 2 18247
2 3 9041
2 4 4031
2 5 7363
3 6 17172
1 7 11014
6 8 14781
8 9 15347
8 10 6598
5 9 19331
3 10 16523
10 6 5732
2 3 20357
6 9 8827
10 3 12864
6 3 1551
5 6 3932
3 1 10223
9 3 2296
8 5 13620

output:

54418

result:

ok single line: '54418'

Test #7:

score: -10
Wrong Answer
time: 0ms
memory: 3792kb

input:

10 20 6 10
1 2 18401
2 3 9843
3 4 4219
4 5 7552
4 6 17751
4 7 11318
5 8 14774
8 9 15541
5 10 6928
6 10 19860
10 5 16699
5 8 5937
5 2 20611
1 8 8077
10 1 12386
9 4 1663
9 10 3910
1 9 10401
7 10 2383
2 9 13681

output:

60711

result:

wrong answer 1st lines differ - expected: 'nonnondayo', found: '60711'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Wrong Answer

Test #21:

score: 10
Accepted
time: 111ms
memory: 8100kb

input:

9992 99999 500 1
1 2 96661121
1 3 21915940
1 4 110026320
1 5 37433129
1 6 38560320
1 7 83209024
1 8 80352054
1 9 88957672
1 10 65449874
1 11 38239186
1 12 90153728
1 13 30810974
1 14 96493404
1 15 112886259
1 16 87190053
1 17 91182163
1 18 107303768
1 19 101439823
1 20 120601875
1 21 122197599
1 22 ...

output:

112890891818

result:

ok single line: '112890891818'

Test #22:

score: 0
Accepted
time: 112ms
memory: 8492kb

input:

9992 99999 1 1
1 2 96660674
2 3 21916518
2 4 110026286
2 5 37432719
4 6 38560294
5 7 83209368
7 8 80352797
2 9 88957012
6 10 65449023
8 11 38237968
3 12 90153572
12 13 30810767
12 14 96493398
9 15 112886094
8 16 87190517
2 17 91182246
5 18 107304167
15 19 101440398
16 20 120601474
13 21 122197537
21...

output:

74448057849

result:

ok single line: '74448057849'

Test #23:

score: 0
Accepted
time: 113ms
memory: 9156kb

input:

9996 99999 2000 1
1 2 96660545
1 3 21916931
1 4 110026628
1 5 37432991
1 6 38561067
1 7 83208951
1 8 80351952
1 9 88957054
1 10 65449457
1 11 38238861
1 12 90154656
1 13 30811324
1 14 96493311
1 15 112885579
1 16 87189959
1 17 91182035
1 18 107304613
1 19 101440492
1 20 120602368
1 21 122197999
1 22...

output:

222817867069

result:

ok single line: '222817867069'

Test #24:

score: 0
Accepted
time: 111ms
memory: 8636kb

input:

9998 99999 6000 1
1 2 96661358
1 3 21916728
1 4 110026601
1 5 37432478
1 6 38560240
1 7 83209841
1 8 80352730
1 9 88957089
1 10 65450089
1 11 38238321
1 12 90153969
1 13 30810766
1 14 96493287
1 15 112885621
1 16 87190068
1 17 91181672
1 18 107303705
1 19 101440812
1 20 120601672
1 21 122197495
1 22...

output:

514650883971

result:

ok single line: '514650883971'

Test #25:

score: -10
Wrong Answer
time: 105ms
memory: 7364kb

input:

9995 99999 8000 1
1 2 96661390
1 3 21916323
1 4 110026027
1 5 37433293
1 6 38560397
1 7 83209785
1 8 80352815
1 9 88957405
1 10 65449996
1 11 38238934
1 12 90153822
1 13 30811526
1 14 96493201
1 15 112885855
1 16 87190720
1 17 91181544
1 18 107304307
1 19 101440244
1 20 120601746
1 21 122196886
1 22...

output:

75111989284

result:

wrong answer 1st lines differ - expected: 'nonnondayo', found: '75111989284'

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%