QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#207940#6560. Broken Minimum Spanning TreeFreeuni1#RE 8ms4052kbC++142.1kb2023-10-08 23:35:142023-10-08 23:35:14

Judging History

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

  • [2023-10-08 23:35:14]
  • 评测
  • 测评结果:RE
  • 用时:8ms
  • 内存:4052kb
  • [2023-10-08 23:35:14]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
    int n, m, k;
vector<array<int, 4> > v, v1;
vector<array<int, 2> > w[2222];
int d[2222], ok[3333];
vector<array<int, 2> > ans;

int gpar(int a) {
    if (d[a] == a) return a;
    return d[a] = gpar(d[a]);
}

bool dsu(int a, int b) {
    a = gpar(a);
    b = gpar(b);
    if (a == b) {
        return false;
    }
    d[a] = b;
    return true;
}

int dfs(int idx, int par, int tar, int ans) {
    //cout << idx << "< >" << tar << endl;

    if (idx == tar) {
        return ans;
    }
    for (auto it: w[idx]) {
        if (it[0] == par) {
            continue;
        }
        //cout << it[1] << "!!";
        if (ans == -1 && ok[it[1]] && it[1] >= n-1) {

            int pas = dfs(it[0], idx, tar, it[1]);
            if (pas != -1) {
                return pas;
            }
        } else if (ok[it[1]]) {
            int pas = dfs(it[0], idx, tar, ans);
            if (pas != -1) {
                return pas;
            }
        }
    }
    return -1;
}
main() {
    cin >> n >> m;
    for (int i = 0; i < m; i ++) {
        int a, s, h;
        cin >> a >> s >> h;
        v.push_back({h, i, a, s});
        v1.push_back({h, i, a, s});
        w[a].push_back({s, i});
        w[s].push_back({a, i});
    }

    sort(v.begin(), v.end());
    for (int i = 1; i <= n; i ++) {
        d[i] = i;
    }

    for (int i = 0; i < m; i ++) {
        if (dsu(v[i][2], v[i][3])) {
            ok[v[i][1]] = 1;
        }
    }
    int j = 0;
    for (int i = 0; i < n - 1; i ++) {
        if (!ok[i]) {
            ans.push_back({i, 0});
        }
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i ++) {
        ans[i][1] = dfs(v1[ans[i][0]][2], -1, v1[ans[i][0]][3], -1);
        assert(ans[i][1] >= 0);
        assert(v1[ans[i][0]][0] > v1[ans[i][1]][0]);
        ok[ans[i][0]] = 1;
        ok[ans[i][1]] = 0;
    }
    reverse(ans.begin(), ans.end());

    for (int i = 0; i < ans.size(); i ++) {
        cout << ans[i][0]+1 << " " << ans[i][1] + 1 << endl;
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3784kb

input:

4 4
1 2 10
2 3 3
3 4 1
1 4 4

output:

1
1 4

result:

ok correct!

Test #2:

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

input:

6 8
1 2 10
2 3 10
3 4 10
4 5 10
5 6 10
6 1 10
1 3 1
4 6 1

output:

2
5 8
2 7

result:

ok correct!

Test #3:

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

input:

2000 1999
1262 1505 968661582
323 1681 787089412
1132 129 88786681
1909 587 762050278
979 1371 230688681
1686 521 980519364
975 191 887826021
869 461 899130441
1433 259 961154249
1718 547 721696188
1254 1042 458319755
1779 267 85751052
1170 813 283230029
309 20 971682908
224 417 255325364
1084 986 7...

output:

0

result:

ok correct!

Test #4:

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

input:

1999 1998
1757 1820 444157563
1757 395 754598547
1757 1571 432619009
1757 1009 456234067
1757 824 935569725
1757 1698 476714469
1757 1420 901765343
1757 1175 225295107
1757 1512 721959801
1757 1585 955067704
1757 1739 635181418
1757 1686 891225461
1757 84 132683224
1757 1696 48915557
1757 1623 42602...

output:

0

result:

ok correct!

Test #5:

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

input:

1999 1998
1345 647 232183406
40 837 279910457
819 857 137486924
255 1378 517489941
827 1565 894953662
1556 1545 898170464
965 877 72248541
1631 298 635713424
895 197 366305735
966 1160 515776809
1870 1638 220711661
1736 220 716014108
1914 1609 759121968
1293 153 272816132
1936 1433 263859075
985 460...

output:

0

result:

ok correct!

Test #6:

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

input:

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

output:

0

result:

ok correct!

Test #7:

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

input:

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

output:

0

result:

ok correct!

Test #8:

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

input:

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

output:

499
499 998
498 997
497 996
496 995
495 994
494 993
493 992
492 991
491 990
490 989
489 988
488 987
487 986
486 985
485 984
484 983
483 982
482 981
481 980
480 979
479 978
478 977
477 976
476 975
475 974
474 973
473 972
472 971
471 970
470 969
469 968
468 967
467 966
466 965
465 964
464 963
463 962
...

result:

ok correct!

Test #9:

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

input:

500 998
198 227 1
227 315 1
315 426 1
426 400 1
400 61 1
61 143 1
143 487 1
487 65 1
65 415 1
415 434 1
434 327 1
327 190 1
190 411 1
411 51 1
51 91 1
91 364 1
364 185 1
185 393 1
393 89 1
89 53 1
53 66 1
66 69 1
69 13 1
13 5 1
5 45 1
45 314 1
314 291 1
291 490 1
490 92 1
92 175 1
175 458 1
458 218 ...

output:

0

result:

ok correct!

Test #10:

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

input:

500 998
360 250 1
250 71 1
71 170 1
170 492 1
492 419 1
419 145 1
145 188 1
188 433 1
433 186 1
186 161 1
161 398 1
398 19 1
19 479 1
479 401 1
401 40 1
40 176 1
176 212 1
212 353 1
353 290 1
290 43 1
43 322 1
322 447 1
447 47 1
47 468 1
468 456 1
456 343 1
343 339 1
339 52 1
52 251 1
251 130 1
130 ...

output:

0

result:

ok correct!

Test #11:

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

input:

500 998
369 45 2
45 364 2
364 300 2
300 195 2
195 291 2
291 390 2
390 122 2
122 331 2
331 408 2
408 91 2
91 298 2
298 116 2
116 301 2
301 287 2
287 338 2
338 4 2
4 79 2
79 177 2
177 387 2
387 125 2
125 477 2
477 11 2
11 284 2
284 102 2
102 305 2
305 395 2
395 112 2
112 280 2
280 294 2
294 232 2
232 ...

output:

499
499 811
498 548
497 666
496 751
495 750
494 672
493 522
492 741
491 582
490 523
489 816
488 817
487 657
486 908
485 906
484 504
483 503
482 955
481 828
480 860
479 740
478 954
477 734
476 718
475 565
474 853
473 958
472 673
471 767
470 877
469 628
468 785
467 878
466 910
465 815
464 781
463 772
...

result:

ok correct!

Test #12:

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

input:

500 998
298 314 1
467 314 1
9 314 1
345 298 1
497 298 1
315 467 1
147 345 1
154 345 1
16 345 1
226 497 1
406 147 1
204 298 1
351 406 1
432 314 1
274 406 1
340 274 1
395 226 1
173 315 1
180 274 1
207 9 1
495 204 1
213 298 1
413 207 1
450 204 1
25 147 1
161 497 1
231 180 1
175 467 1
199 231 1
454 231 ...

output:

0

result:

ok correct!

Test #13:

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

input:

500 998
42 349 1
256 42 1
202 349 1
23 42 1
252 42 1
175 42 1
67 252 1
302 67 1
337 252 1
495 252 1
14 349 1
347 202 1
494 495 1
206 347 1
1 302 1
434 349 1
475 206 1
243 206 1
135 494 1
179 495 1
226 202 1
490 226 1
481 1 1
165 243 1
114 495 1
463 256 1
282 114 1
411 202 1
25 1 1
163 67 1
388 179 1...

output:

0

result:

ok correct!

Test #14:

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

input:

500 998
493 328 2
444 493 2
356 328 2
374 328 2
135 328 2
292 444 2
323 135 2
296 328 2
407 493 2
207 374 2
118 296 2
490 135 2
357 323 2
464 292 2
279 323 2
183 493 2
81 356 2
367 407 2
235 356 2
354 292 2
479 464 2
214 118 2
406 357 2
164 279 2
230 356 2
380 164 2
399 135 2
344 81 2
190 490 2
422 ...

output:

499
499 998
498 997
497 996
496 995
495 994
494 993
493 992
492 991
491 990
490 989
489 988
488 987
487 986
486 985
485 984
484 983
483 982
482 981
481 980
480 979
479 978
478 977
477 976
476 975
475 974
474 973
473 972
472 971
471 970
470 969
469 968
468 967
467 966
466 965
465 964
464 963
463 962
...

result:

ok correct!

Test #15:

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

input:

10 20
3 5 132699872
7 3 667475629
10 7 829222331
1 7 265644695
4 3 226461311
2 7 720348681
6 10 703702759
8 4 153004599
9 10 646988804
1 9 45480111
2 4 784301144
1 9 628023542
7 8 449200681
9 2 240371799
3 2 420603433
3 9 838425734
4 6 623790050
1 7 513829155
1 9 883183260
10 3 422484921

output:

5
9 14
7 17
6 15
3 20
2 10

result:

ok correct!

Test #16:

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

input:

100 200
69 52 334673965
90 52 598347660
62 52 671196898
38 90 561150605
97 69 844448459
25 90 865251171
41 38 773653441
49 97 813975775
99 41 996226580
54 69 583281785
34 38 385173507
56 97 285801905
17 38 946715780
67 17 139770128
43 97 890101081
68 90 370458274
74 17 698466900
6 67 19950896
58 56 ...

output:

50
96 107
95 185
92 125
89 152
87 109
83 197
81 176
80 126
77 103
75 135
74 115
71 192
69 190
67 145
65 181
64 148
61 160
60 166
58 120
52 150
50 195
49 174
47 112
45 180
44 168
41 136
39 156
36 127
35 171
31 194
28 108
25 104
24 137
23 186
21 132
20 196
19 157
17 183
16 131
15 121
13 163
10 170
9 1...

result:

ok correct!

Test #17:

score: 0
Accepted
time: 8ms
memory: 4004kb

input:

2000 3000
1279 1465 434468566
1062 1279 993799662
1494 1465 490141333
529 1279 207090506
119 1279 494706603
1830 1062 798435525
1307 1279 501822892
362 119 776215279
1330 1494 64095945
1823 529 302809447
1882 529 298925061
1394 529 639185117
1852 362 939130818
752 529 845078929
104 752 853251112
126...

output:

617
1992 2764
1991 2321
1986 2934
1984 2470
1979 2375
1976 2727
1975 2003
1974 2358
1969 2411
1964 2452
1963 2425
1961 2839
1958 2329
1955 2464
1953 2083
1946 2656
1938 2792
1937 2408
1936 2284
1934 2796
1927 2832
1924 2260
1921 2357
1919 2807
1915 2805
1903 2784
1902 2503
1897 2991
1896 2994
1894 2...

result:

ok correct!

Test #18:

score: 0
Accepted
time: 8ms
memory: 3992kb

input:

2000 3000
285 1808 694643588
224 285 690510187
908 1808 663193044
486 224 663712643
324 908 165916788
1403 285 948845412
1310 324 12561437
1948 285 642808470
883 1310 358793640
396 1808 869731392
1276 1310 621641177
203 1948 231802320
1547 1276 39692873
830 285 636658714
1357 1948 177401445
303 203 ...

output:

613
1999 2487
1992 2767
1991 2453
1989 2482
1987 2367
1983 2963
1977 2234
1974 2466
1972 2608
1965 2720
1960 2414
1957 2566
1950 2467
1946 2295
1942 2560
1939 2080
1938 2578
1930 2499
1927 2019
1926 2514
1920 2130
1916 2398
1909 2187
1902 2445
1901 2969
1893 2516
1892 2923
1886 2515
1879 2256
1875 2...

result:

ok correct!

Test #19:

score: 0
Accepted
time: 8ms
memory: 4052kb

input:

2000 3000
1966 1337 886061561
1564 1966 321739163
878 1966 383102115
15 1337 355428698
392 15 389233814
1520 1337 163779508
1349 392 323493610
1126 1349 804548395
1739 1337 508691040
956 1564 924027693
674 1126 845489957
1749 1739 290423046
1926 1966 647294733
456 1966 656155212
1746 1564 106274278
...

output:

603
1998 2480
1992 2387
1985 2418
1982 2315
1977 2723
1974 2602
1967 2857
1962 2605
1961 2617
1958 2269
1956 2086
1954 2308
1953 2670
1949 2999
1947 2718
1942 2326
1939 2579
1928 2584
1927 2433
1926 2859
1923 2112
1922 2583
1919 2203
1918 2590
1917 2442
1913 2930
1911 2854
1909 2460
1908 2690
1895 2...

result:

ok correct!

Test #20:

score: -100
Runtime Error

input:

2000 3000
487 1828 891595258
848 1828 70120465
399 1828 222566316
2000 1828 390057442
589 487 561090448
1878 399 923567050
1547 848 289163461
724 1828 712597149
856 487 612088317
1932 848 498697630
177 1932 225589816
1541 856 745128386
1229 399 501103338
40 1828 283700123
1206 1878 364593718
519 40 ...

output:

624

result: