QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#275613 | #7883. Takeout Delivering | ucup-team902 | AC ✓ | 223ms | 49200kb | C++20 | 2.0kb | 2023-12-04 21:34:55 | 2023-12-06 23:03:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define gc c=getchar()
#define r(x) read(x)
#define ll long long
template<typename T>
inline void read(T &x){
x=0;T k=1;char gc;
while(!isdigit(c)){if(c=='-')k=-1;gc;}
while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
}
const int N = 3e5 + 7;
int fa[N];
vector<int> ele[N];
int mx1[N];
int mxn[N];
int find(int x){
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int n, m; r(n), r(m);
vector<pair<int, pair<int, int>>> edges;
for(int i = 1; i <= m; ++i){
int u, v, w; r(u), r(v), r(w);
edges.push_back({w, {u, v}});
}
sort(edges.begin(), edges.end());
for(int i = 1; i <= n; ++i){
fa[i] = i;
ele[i].push_back(i);
}
for(auto &e : edges){
int w = e.first;
int u = e.second.first;
int v = e.second.second;
u = find(u);
v = find(v);
if(u == v) continue;
if(u == find(1)) for(auto &x: ele[v]) mx1[x] = w;
if(v == find(1)) for(auto &x: ele[u]) mx1[x] = w;
if(u == find(n)) for(auto &x: ele[v]) mxn[x] = w;
if(v == find(n)) for(auto &x: ele[u]) mxn[x] = w;
if(ele[u].size() < ele[v].size()) swap(u, v);
// ele[u].insert(ele[u].end(), ele[v].begin(), ele[v].end());
for(auto &x: ele[v]) ele[u].push_back(x);
ele[v].clear();
fa[v] = u;
}
int ans = 2e9;
for(auto &e : edges){
int w = e.first;
int u = e.second.first;
int v = e.second.second;
if(abs(u - v) == n - 1){
ans = min(ans, w);
}
else{
if(mx1[u] <= w && mxn[v] <= w){
ans = min(ans, w + max(mx1[u], mxn[v]));
}
if(mx1[v] <= w && mxn[v] <= w){
ans = min(ans, w + max(mx1[v], mxn[u]));
}
}
}
printf("%d\n", ans);
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 12052kb
input:
4 6 1 2 2 1 3 4 1 4 7 2 3 1 2 4 3 3 4 9
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 81ms
memory: 41156kb
input:
300000 299999 80516 80517 597830404 110190 110191 82173886 218008 218009 954561262 250110 250111 942489774 66540 66541 156425292 34947 34948 239499776 273789 273790 453201232 84428 84429 439418398 98599 98600 326095035 55636 55637 355015760 158611 158612 684292473 43331 43332 43265001 171621 171622 ...
output:
1999991697
result:
ok 1 number(s): "1999991697"
Test #3:
score: 0
Accepted
time: 81ms
memory: 35652kb
input:
300000 299999 207226 231742 414945003 84591 210444 175968953 46327 51582 612565723 18773 141119 82562646 76139 286963 762958587 131867 224820 928900783 215240 216181 405340417 144725 290878 195350550 267216 268752 846015171 31413 255927 389339642 45219 147512 489502910 113391 215402 555706684 53359 ...
output:
1989898633
result:
ok 1 number(s): "1989898633"
Test #4:
score: 0
Accepted
time: 70ms
memory: 31048kb
input:
300000 299999 1 118488 989720257 1 181002 810258689 1 254222 172925351 1 176703 737330574 1 218306 941887568 1 105741 645573853 1 188490 794789787 1 273997 91455946 1 214929 293300204 1 127289 600097406 1 30589 330284120 1 128954 532459734 1 163729 627033607 1 24073 718818252 1 41571 755054850 1 560...
output:
725564985
result:
ok 1 number(s): "725564985"
Test #5:
score: 0
Accepted
time: 71ms
memory: 36340kb
input:
300000 299999 19784 19785 438457172 153297 239456 192671538 153297 202254 645947104 9640 9641 583410541 153297 221084 490232940 32210 32211 838809517 153297 171896 625627853 153297 216946 683286844 110843 110844 690710575 153297 176413 983037656 74908 74909 375017711 67676 67677 695121437 153297 196...
output:
1999992880
result:
ok 1 number(s): "1999992880"
Test #6:
score: 0
Accepted
time: 94ms
memory: 40860kb
input:
300000 299999 130662 244000 579178004 167657 294630 753914681 61924 61925 165841675 113560 113561 979316325 151574 218075 973289843 1224 1225 230803236 133441 133442 806726301 167309 249456 853031541 120245 120246 688705252 142688 217826 692299631 106114 106115 735998084 123268 123269 749737073 1208...
output:
1999989691
result:
ok 1 number(s): "1999989691"
Test #7:
score: 0
Accepted
time: 81ms
memory: 34216kb
input:
300000 299999 54474 108948 971770803 11077 22155 470962125 115359 230718 373029049 124472 248944 865510218 11958 23917 100575860 130349 260698 582886291 17563 35127 697131917 54427 108854 274252758 51546 103092 198620066 100126 200252 154524070 14994 29988 528701437 147502 295004 531813162 42285 845...
output:
1823402145
result:
ok 1 number(s): "1823402145"
Test #8:
score: 0
Accepted
time: 80ms
memory: 39060kb
input:
300000 299999 240182 240189 427579190 41871 41880 360542232 57131 57140 353813367 122650 122653 621913649 67332 67340 271427538 107523 107524 774306311 60374 60379 315636931 130805 130808 667109508 154531 154534 327293148 138561 138569 833879694 32543 32551 382610722 287398 287400 211744079 59693 59...
output:
1999983202
result:
ok 1 number(s): "1999983202"
Test #9:
score: 0
Accepted
time: 3ms
memory: 13984kb
input:
10 20 1 6 98 3 4 3 4 5 26 7 8 72 1 2 86 3 7 83 7 10 89 4 7 100 3 6 59 6 9 74 5 6 28 6 7 1 2 9 100 2 6 99 5 10 85 8 10 97 2 10 98 8 9 3 2 3 94 9 10 71
output:
170
result:
ok 1 number(s): "170"
Test #10:
score: 0
Accepted
time: 0ms
memory: 12424kb
input:
10 20 2 8 94 3 7 81 8 10 85 2 4 88 4 5 90 1 4 96 3 6 95 7 10 77 1 8 98 4 7 91 2 6 38 1 10 89 1 3 45 4 9 94 3 9 64 6 10 83 5 8 19 2 5 81 6 7 92 3 4 92
output:
89
result:
ok 1 number(s): "89"
Test #11:
score: 0
Accepted
time: 2ms
memory: 12308kb
input:
10 20 1 6 58 1 4 80 1 10 28 1 3 46 6 7 76 7 10 75 4 9 95 2 10 92 1 7 15 9 10 52 3 6 93 5 7 94 1 2 75 1 5 41 3 7 79 4 8 94 2 6 80 6 9 63 1 9 42 1 8 9
output:
28
result:
ok 1 number(s): "28"
Test #12:
score: 0
Accepted
time: 1ms
memory: 11888kb
input:
10 20 6 9 79 5 6 72 2 5 74 2 4 74 8 10 90 1 5 82 3 4 55 6 10 94 7 8 55 3 7 92 1 8 83 9 10 93 4 7 98 4 5 24 2 3 28 6 7 24 1 2 63 3 10 99 8 9 2 5 10 95
output:
158
result:
ok 1 number(s): "158"
Test #13:
score: 0
Accepted
time: 0ms
memory: 12476kb
input:
10 20 3 4 75 5 7 98 3 10 91 5 8 41 2 7 84 2 3 73 4 10 100 2 4 80 1 5 99 3 9 79 4 5 97 4 9 10 4 7 52 1 10 96 8 10 98 6 9 99 1 2 50 5 9 98 2 9 93 3 6 92
output:
96
result:
ok 1 number(s): "96"
Test #14:
score: 0
Accepted
time: 2ms
memory: 13932kb
input:
10 20 1 5 84 9 10 98 2 3 56 2 4 5 3 9 95 4 9 94 3 7 82 6 8 68 1 3 10 4 8 64 3 6 46 5 10 58 5 7 92 6 7 96 1 2 38 2 5 74 1 8 70 8 9 100 4 7 93 7 9 98
output:
132
result:
ok 1 number(s): "132"
Test #15:
score: 0
Accepted
time: 2ms
memory: 11956kb
input:
10 20 2 10 100 8 10 100 7 10 85 3 7 73 5 7 100 4 9 100 1 8 7 2 4 26 6 8 27 3 4 100 6 7 100 2 3 99 3 9 66 9 10 13 4 8 75 1 2 8 4 10 100 1 6 19 7 9 99 2 5 49
output:
107
result:
ok 1 number(s): "107"
Test #16:
score: 0
Accepted
time: 0ms
memory: 14084kb
input:
100 200 60 77 957 70 71 589 63 64 915 13 79 1000 8 9 757 41 42 141 21 53 1000 82 99 911 58 59 683 62 63 889 92 93 455 71 72 457 11 92 1000 9 43 1000 94 95 582 57 58 606 54 55 162 27 28 732 99 100 256 42 43 201 13 99 1000 15 73 1000 19 20 646 22 91 1000 22 50 1000 93 94 888 14 15 904 10 47 1000 68 83...
output:
1671
result:
ok 1 number(s): "1671"
Test #17:
score: 0
Accepted
time: 2ms
memory: 11952kb
input:
100 200 21 59 969 4 22 998 47 98 637 8 51 982 48 55 995 14 65 22 3 35 987 40 46 969 6 82 432 13 98 960 24 49 965 5 32 571 20 71 617 71 82 982 30 66 979 76 79 255 7 56 965 18 21 971 53 65 81 63 64 991 6 88 949 1 13 995 31 38 405 40 91 952 47 89 956 8 84 475 29 90 202 6 12 975 30 89 509 47 88 82 4 58 ...
output:
1859
result:
ok 1 number(s): "1859"
Test #18:
score: 0
Accepted
time: 1ms
memory: 11980kb
input:
100 200 19 29 909 22 86 785 1 56 28 38 85 942 1 52 89 1 78 693 4 30 975 54 99 939 1 89 461 1 59 390 1 95 576 1 92 343 1 11 876 1 85 109 29 78 958 74 81 981 10 49 799 1 39 767 41 92 641 1 69 149 1 34 984 13 70 896 32 44 949 1 20 137 1 90 85 2 70 545 4 58 910 33 60 818 89 96 906 66 100 997 1 55 85 1 9...
output:
896
result:
ok 1 number(s): "896"
Test #19:
score: 0
Accepted
time: 2ms
memory: 11948kb
input:
100 200 11 89 997 30 81 985 58 62 260 23 29 995 58 97 909 69 91 986 58 83 597 11 12 858 58 98 213 58 93 465 8 9 638 5 79 996 58 91 659 37 98 990 47 50 993 43 61 986 37 81 997 58 75 102 22 64 998 4 23 990 41 87 1000 73 95 982 30 31 722 13 43 998 17 18 659 42 52 974 32 48 939 53 90 996 69 86 943 4 5 2...
output:
1943
result:
ok 1 number(s): "1943"
Test #20:
score: 0
Accepted
time: 0ms
memory: 11896kb
input:
100 200 14 21 980 1 2 23 61 80 984 51 52 626 1 71 828 31 32 797 60 61 436 17 61 957 35 73 85 30 37 879 48 72 267 53 54 482 7 91 997 37 88 576 26 74 996 50 93 998 8 75 993 30 80 809 26 40 866 23 89 969 60 77 964 44 80 964 28 68 899 17 100 995 47 92 989 57 58 630 35 36 291 36 37 70 18 20 888 12 99 892...
output:
427
result:
ok 1 number(s): "427"
Test #21:
score: 0
Accepted
time: 2ms
memory: 11952kb
input:
100 200 11 12 980 33 66 341 60 88 997 41 83 156 11 22 995 29 75 736 44 73 996 8 68 965 49 62 935 65 81 998 5 10 229 58 74 934 55 88 998 27 90 999 10 21 409 3 74 911 11 84 1000 9 95 988 3 6 393 16 61 956 34 88 1000 34 67 966 21 43 66 12 61 837 14 56 413 12 42 998 26 52 778 6 12 830 63 78 844 6 36 893...
output:
1505
result:
ok 1 number(s): "1505"
Test #22:
score: 0
Accepted
time: 1ms
memory: 12244kb
input:
100 200 83 88 101 56 59 191 64 71 419 7 26 927 48 57 69 9 41 741 43 67 993 21 56 916 20 22 801 35 42 973 78 85 138 26 50 924 87 96 727 19 96 997 9 26 848 21 28 820 39 49 537 47 72 900 55 63 672 18 19 109 9 60 923 8 82 988 8 18 795 9 34 618 23 28 649 67 68 366 10 12 500 23 38 819 10 17 815 69 99 998 ...
output:
1402
result:
ok 1 number(s): "1402"
Test #23:
score: 0
Accepted
time: 212ms
memory: 48488kb
input:
300000 1000000 279851 289752 999954614 161068 161069 686040658 98775 290773 999996999 152639 152640 726594968 83070 83071 812508473 91034 126281 999954538 86789 222983 999990457 95587 176851 999991161 33638 137265 999988809 84658 192641 999991026 153523 295952 999998616 174583 243251 999987129 12518...
output:
1998201565
result:
ok 1 number(s): "1998201565"
Test #24:
score: 0
Accepted
time: 207ms
memory: 43696kb
input:
300000 1000000 156094 177846 999756574 62670 67365 998445252 208162 262938 951223122 4473 299766 999848707 55716 259406 991999708 200961 289293 999630537 226488 296872 999957282 60230 184345 693085189 63378 232935 999103539 170802 291169 998305128 138174 147828 999661605 7372 30652 999808376 19294 1...
output:
1984419418
result:
ok 1 number(s): "1984419418"
Test #25:
score: 0
Accepted
time: 180ms
memory: 38232kb
input:
300000 1000000 1 147883 857171646 218469 281753 668868929 87069 88444 765722112 80658 226298 847902531 52585 138505 745740009 55501 299252 995334032 22818 250405 984578623 143157 208305 995152517 5904 95707 811106518 86088 239508 980889473 11951 88291 984206415 90833 181809 922003327 1 92676 4902585...
output:
343702423
result:
ok 1 number(s): "343702423"
Test #26:
score: 0
Accepted
time: 223ms
memory: 48048kb
input:
300000 1000000 9446 156375 999999082 31845 169221 999996900 47754 161175 999999754 232072 232073 779152510 76046 108751 999994616 164977 179173 999925027 124378 124379 203717841 112741 166667 999999373 74038 84489 999931917 86735 225832 999998530 142866 271861 999996927 190990 293596 999996937 28233...
output:
1953412447
result:
ok 1 number(s): "1953412447"
Test #27:
score: 0
Accepted
time: 215ms
memory: 49200kb
input:
300000 1000000 222321 222322 9886022 138391 157917 999998292 145717 145718 820134733 9170 227813 999999300 63322 204740 999996784 253229 286449 999988567 214588 214589 960728881 107540 202712 999997179 123320 123321 101442049 22390 130243 999999341 232683 288477 999998849 199798 199799 545065335 346...
output:
1994280264
result:
ok 1 number(s): "1994280264"
Test #28:
score: 0
Accepted
time: 209ms
memory: 40760kb
input:
300000 1000000 40119 80239 44171905 80901 293693 991077675 106189 163039 976788224 80773 170764 980829184 40872 81745 734308424 81955 163910 899177952 17072 34144 566527870 149412 256390 985425893 92624 185249 545173846 144763 177976 997132425 131048 224105 993051723 269791 292032 998886095 64672 66...
output:
1782662388
result:
ok 1 number(s): "1782662388"
Test #29:
score: 0
Accepted
time: 219ms
memory: 47280kb
input:
300000 1000000 234869 279009 999983868 144072 209459 999979884 89106 89114 680440461 131152 137107 998064364 15365 83929 999893390 88712 261682 999992137 32874 32879 107546865 15554 156038 999984486 11365 164157 999992300 3290 294690 999988694 58570 104308 999884389 84125 84130 738178843 196409 2813...
output:
1983333851
result:
ok 1 number(s): "1983333851"
Test #30:
score: 0
Accepted
time: 2ms
memory: 12008kb
input:
100 200 65 66 304 74 75 740 15 73 1000 76 77 668 20 77 1000 84 85 430 14 15 904 89 90 687 78 79 601 12 13 36 63 96 970 28 29 271 45 46 122 5 6 117 2 96 1000 46 84 977 50 93 950 95 96 471 7 92 1000 33 48 1000 24 27 929 50 51 609 31 70 1000 88 89 167 36 41 1000 51 67 998 91 92 148 75 76 70 9 43 1000 5...
output:
1000
result:
ok 1 number(s): "1000"
Test #31:
score: 0
Accepted
time: 0ms
memory: 12008kb
input:
100 200 25 44 53 40 46 969 53 66 306 61 78 751 6 27 885 17 54 831 77 81 588 19 28 481 4 58 932 11 82 501 71 82 982 81 91 803 25 67 972 40 91 952 32 37 491 47 98 637 24 29 971 36 82 742 32 96 485 29 86 320 48 72 754 1 90 963 1 9 897 14 16 984 48 50 1000 13 72 687 25 74 966 37 41 991 17 34 568 76 79 2...
output:
1000
result:
ok 1 number(s): "1000"
Test #32:
score: 0
Accepted
time: 2ms
memory: 12404kb
input:
100 200 19 29 909 22 86 785 1 56 28 38 85 942 1 52 89 1 78 693 4 30 975 54 99 939 1 89 461 1 59 390 1 95 576 1 92 343 1 11 876 1 85 109 29 78 958 74 81 981 10 49 799 1 39 767 41 92 641 1 69 149 1 34 984 13 70 896 32 44 949 1 20 137 1 90 85 2 70 545 4 58 910 33 60 818 89 96 906 66 100 997 1 55 85 1 9...
output:
896
result:
ok 1 number(s): "896"
Test #33:
score: 0
Accepted
time: 2ms
memory: 12536kb
input:
100 200 58 59 810 4 23 990 58 77 393 58 82 608 31 95 989 10 26 1000 17 38 995 15 99 996 42 43 120 58 100 950 58 63 324 17 28 998 42 52 974 58 72 160 48 49 770 29 34 741 6 72 996 24 25 399 9 68 998 21 58 995 30 31 722 24 75 993 4 58 993 23 24 992 11 12 858 41 87 1000 74 80 788 58 81 15 16 17 541 21 6...
output:
1000
result:
ok 1 number(s): "1000"
Test #34:
score: 0
Accepted
time: 0ms
memory: 14052kb
input:
100 200 18 19 524 40 41 609 62 63 539 41 42 575 15 32 986 96 99 984 37 78 926 2 3 352 4 90 499 21 95 998 28 68 899 43 44 598 17 24 926 38 39 262 9 10 992 54 96 926 61 80 984 43 45 783 28 71 993 63 64 537 35 73 85 53 54 482 10 66 999 24 25 640 50 93 998 11 68 709 35 99 865 50 97 304 30 94 53 2 69 100...
output:
426
result:
ok 1 number(s): "426"
Test #35:
score: 0
Accepted
time: 2ms
memory: 12004kb
input:
100 200 58 81 936 46 92 775 44 88 252 18 37 131 3 6 393 47 76 983 26 53 739 25 51 280 14 22 999 43 87 961 33 67 448 12 25 875 30 60 120 36 72 829 51 63 890 41 68 939 10 21 409 29 75 736 7 77 740 10 32 991 33 89 998 28 55 997 33 61 972 76 89 999 55 88 998 15 30 236 37 74 639 63 93 999 22 44 420 17 70...
output:
1000
result:
ok 1 number(s): "1000"
Test #36:
score: 0
Accepted
time: 2ms
memory: 12564kb
input:
100 200 21 90 848 41 51 211 96 100 1000 54 56 189 95 97 663 36 39 279 2 54 893 83 88 101 50 100 1000 2 30 907 39 49 537 16 22 882 78 85 138 36 44 48 18 50 941 13 14 717 45 54 794 1 52 922 55 63 672 77 84 958 16 24 166 78 98 1000 42 44 941 80 97 919 49 50 778 5 8 231 30 82 997 87 96 727 19 27 480 9 2...
output:
1000
result:
ok 1 number(s): "1000"
Test #37:
score: 0
Accepted
time: 221ms
memory: 48404kb
input:
300000 1000000 269518 292647 999979767 57782 183195 999999860 52430 270112 999998831 163062 228071 999996604 120698 283794 999997023 92687 92688 496166848 40259 272992 999999519 14505 260611 999995384 51286 181693 999995813 217822 250439 999990459 129004 238452 999988422 217897 217898 744230376 2375...
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #38:
score: 0
Accepted
time: 202ms
memory: 43972kb
input:
300000 1000000 192168 268279 793802137 143828 204038 999989862 86088 196098 999661537 129709 193204 993969460 25489 263515 991036836 79815 213682 999891046 133348 241295 998591163 44060 293416 558757406 94488 145579 77325519 140144 275747 36609902 160045 196172 999567498 32290 167942 999996891 18412...
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #39:
score: 0
Accepted
time: 178ms
memory: 37968kb
input:
300000 1000000 1 147883 857171646 218469 281753 668868929 87069 88444 765722112 80658 226298 847902531 52585 138505 745740009 55501 299252 995334032 22818 250405 984578623 143157 208305 995152517 5904 95707 811106518 86088 239508 980889473 11951 88291 984206415 90833 181809 922003327 1 92676 4902585...
output:
343702423
result:
ok 1 number(s): "343702423"
Test #40:
score: 0
Accepted
time: 204ms
memory: 48536kb
input:
300000 1000000 506 184027 999995684 252536 255173 999823461 246213 284359 999993950 234918 234919 685197761 122952 122953 28511965 84475 268606 999997644 208182 250914 999998659 43489 127113 999997790 107107 107108 412487495 55663 149501 999998989 208113 294917 999997425 47416 299118 999998165 22857...
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #41:
score: 0
Accepted
time: 218ms
memory: 48664kb
input:
300000 1000000 95725 261255 999999710 259968 259969 574023541 82314 82315 239185600 238575 238576 227551658 146039 146040 659377759 226079 226080 91185106 280466 280467 313532816 157350 281634 999999720 52862 52863 375221527 18661 18662 47282205 182467 243544 999987826 135459 135460 315366048 155211...
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #42:
score: 0
Accepted
time: 194ms
memory: 40548kb
input:
300000 1000000 85330 170660 52578202 124269 222940 981734244 71182 123370 996668814 2297 4595 454260790 153444 237668 973001003 10910 21820 303353048 138914 246169 984550728 63331 126662 207157094 166513 230706 987983718 242050 247296 993455812 121446 242893 496512130 33830 237472 997296735 22285 97...
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #43:
score: 0
Accepted
time: 210ms
memory: 47340kb
input:
300000 1000000 17607 270310 999997919 32933 117860 999896718 141781 204309 999986142 41372 80791 999903153 131569 235648 999992910 22931 22933 879413596 109255 120550 999780163 175303 175312 139524349 200055 200060 478729405 41774 265911 999988421 108472 137638 999955668 111766 158105 999996893 5009...
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #44:
score: 0
Accepted
time: 0ms
memory: 11928kb
input:
2 1 1 2 3
output:
3
result:
ok 1 number(s): "3"
Extra Test:
score: 0
Extra Test Passed