QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200026 | #7343. Bicycle Race | BoulevardDust# | WA | 4551ms | 48808kb | C++20 | 2.3kb | 2023-10-04 15:07:56 | 2023-10-04 15:07:57 |
Judging History
answer
#include <bits/stdc++.h>
#define re
#define m_p make_pair
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
using namespace std;
const int N = 400005;
const int B = 330;
inline void Rd(int &res){
re char c;res=0;
while(c=getchar(),c<48);
do res=(res<<3)+(res<<1)+(c^48);
while(c=getchar(),c>47);
}
int n, m;
int deg[N];
array<int, 3> E[N];
vector<pair<int, int> > G[N];
set<pair<int, int> > S[N];
int ans = -1;
int check(int A, int B) {
if (A == B) return 0;
auto it = S[A].lower_bound(make_pair(B, 0));
if (it != S[A].end() && it -> first == B) return it -> second;
else return 0;
}
int len = 0;
array<int, 3> lis[N];
void add(int u, int v, int val) {
lis[++len] = {val, u, v};
}
int work(int idx) {
int answer = -1;
sort(lis + 1, lis + len + 1);
reverse(lis + 1, lis + len + 1);
int k = min(len, 6);
for (int i = 1; i <= k; ++i) {
for (int j = i + 1; j <= k; ++j) {
int p[5] = {idx, lis[i][1], lis[i][2], lis[j][1], lis[j][2]};
sort(p, p + 5);
bool err = 0;
for (int o = 1; o < 5; ++o) err |= (p[o] == p[o - 1]);
if (!err) {
// outln("aa");
answer = max(answer, lis[i][0] + lis[j][0]);
}
}
}
return answer;
}
void clear() {
len = 0;
}
void Small(int idx) {
int sz = (int)(G[idx].size());
for (int i = 0; i < sz; ++i) {
for (int j = i + 1; j < sz; ++j) {
int u = G[idx][i].first, v = G[idx][j].first;
int p1 = G[idx][i].second;
int p2 = G[idx][j].second;
int p3 = check(u, v);
if (p3) {
// out(idx); out(u); out(v); out(p1); out(p2); outln(p3);
add(u, v, p1 + p2 + p3);
}
}
}
}
void Big(int idx) {
for (int i = 1; i <= m; ++i) {
int u = E[i][0], v = E[i][1], w = E[i][2];
int p1 = check(idx, u);
int p2 = check(idx, v);
if (p1 && p2) {
add(u, v, p1 + p2 + w);
}
}
}
int main() {
Rd(n); Rd(m);
for (int i = 1; i <= m; ++i) {
int u, v, w;
Rd(u); Rd(v); Rd(w);
E[i] = {u, v, w};
G[u].emplace_back(v, w);
G[v].emplace_back(u, w);
S[u].insert(m_p(v, w));
S[v].insert(m_p(u, w));
deg[u] += 1; deg[v] += 1;
}
for (int i = 1; i <= n; ++i) {
if (deg[i] <= B) {
Small(i);
} else {
Big(i);
}
ans = max(ans, work(i));
clear();
}
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 36576kb
input:
6 9 1 2 3 2 3 1 3 4 2 4 5 1 3 5 7 2 5 2 1 5 3 4 6 2 5 6 1
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 4ms
memory: 36580kb
input:
6 6 1 3 2 1 2 2 2 3 4 3 4 1 3 6 6 1 4 8
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 3ms
memory: 36660kb
input:
5 6 1 4 2 1 3 6 5 2 10 3 2 4 4 2 1 5 4 7
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 36536kb
input:
5 10 2 1 9 3 1 4 3 2 3 4 1 5 4 2 9 4 3 9 5 1 5 5 2 6 5 3 10 5 4 1
output:
43
result:
ok 1 number(s): "43"
Test #5:
score: 0
Accepted
time: 4ms
memory: 36600kb
input:
5 10 2 1 9 3 1 8 3 2 8 4 1 1 4 2 2 4 3 8 5 1 10 5 2 1 5 3 10 5 4 3
output:
46
result:
ok 1 number(s): "46"
Test #6:
score: 0
Accepted
time: 4ms
memory: 32416kb
input:
5 9 1 3 4 4 1 10 1 5 9 5 2 9 3 5 9 2 3 7 5 4 1 2 1 7 2 4 1
output:
45
result:
ok 1 number(s): "45"
Test #7:
score: 0
Accepted
time: 3ms
memory: 36724kb
input:
5 8 2 1 10 5 2 5 1 3 7 3 5 8 3 2 5 2 4 6 4 3 5 4 5 6
output:
41
result:
ok 1 number(s): "41"
Test #8:
score: 0
Accepted
time: 7ms
memory: 32736kb
input:
200 2000 182 97 91166 25 11 25393 179 58 43378 77 41 75588 139 96 94145 135 56 4609 190 159 47293 100 30 33854 21 132 93072 174 135 93547 144 137 81216 199 102 68247 89 155 53788 83 25 64607 166 179 44534 101 3 1474 37 106 57970 187 41 19892 16 76 32024 182 13 32061 72 69 5823 187 185 13918 151 86 3...
output:
552426
result:
ok 1 number(s): "552426"
Test #9:
score: 0
Accepted
time: 7ms
memory: 37040kb
input:
400 4000 102 372 24346 360 153 94255 272 316 33427 215 71 52304 368 202 60854 350 206 16796 32 372 31489 109 14 95840 163 71 79896 330 393 95303 324 110 13216 197 341 69668 54 241 46100 222 246 67388 140 13 539 272 79 22065 389 221 81398 187 122 60482 198 352 4291 196 14 18220 215 93 64141 336 54 54...
output:
545402
result:
ok 1 number(s): "545402"
Test #10:
score: 0
Accepted
time: 12ms
memory: 37288kb
input:
600 6000 270 248 73879 94 543 63116 118 174 23476 152 301 12668 597 557 27564 566 156 28983 322 585 15685 319 598 41474 506 411 50369 334 450 80707 103 83 61569 195 333 71089 219 576 54764 409 18 70169 115 296 72896 92 155 42655 542 537 4827 387 202 1071 209 15 4380 511 165 22459 485 571 94537 570 2...
output:
545966
result:
ok 1 number(s): "545966"
Test #11:
score: 0
Accepted
time: 7ms
memory: 33476kb
input:
800 8000 391 123 23412 629 133 31977 411 31 13525 489 131 89384 427 512 94273 29 506 24818 564 397 99881 528 382 3460 448 702 20841 290 156 82464 235 56 9922 192 772 88862 784 63 47076 148 591 72950 490 531 45253 263 231 63246 295 453 44608 234 683 58012 562 56 32475 671 464 90539 454 237 97128 635 ...
output:
537316
result:
ok 1 number(s): "537316"
Test #12:
score: 0
Accepted
time: 15ms
memory: 37744kb
input:
900 9000 751 713 98178 420 281 8232 734 560 50374 234 645 19566 641 65 77628 537 681 89087 561 4 33803 457 274 26277 367 372 56077 816 485 16990 425 42 67747 543 144 89573 43 230 93232 441 701 66164 801 772 31431 773 392 73541 771 535 6323 634 271 20131 429 870 52257 54 265 33619 425 148 84463 285 6...
output:
543761
result:
ok 1 number(s): "543761"
Test #13:
score: 0
Accepted
time: 12ms
memory: 33644kb
input:
1000 10000 474 791 31535 814 802 77941 268 530 73504 935 202 16680 294 563 90749 295 865 28879 881 407 92656 170 489 69207 647 539 16716 588 994 32698 450 999 67004 450 85 62626 88 759 97603 375 910 48465 855 380 62615 581 791 48023 692 533 10312 249 752 93019 229 570 80407 135 31 24826 158 458 2555...
output:
535602
result:
ok 1 number(s): "535602"
Test #14:
score: 0
Accepted
time: 4549ms
memory: 48808kb
input:
500 100000 2 1 54424 3 1 48973 3 2 86095 4 1 76564 4 2 82172 4 3 86663 5 1 24522 5 2 37933 5 3 67602 5 4 17497 6 1 53084 6 2 41172 6 3 52523 6 4 91108 6 5 84953 7 1 594 7 2 61541 7 3 90638 7 4 34896 7 5 73592 7 6 62931 8 2 72346 8 5 16373 8 7 95438 9 1 19930 9 2 89438 9 3 2195 9 4 71744 9 5 1168 9 6...
output:
596558
result:
ok 1 number(s): "596558"
Test #15:
score: 0
Accepted
time: 4551ms
memory: 48100kb
input:
500 100000 2 1 2692 3 2 10621 4 1 60135 4 2 56741 5 1 66724 5 2 46777 5 3 72456 5 4 41383 6 1 24952 6 2 86 6 3 50877 6 4 14549 6 5 12700 7 1 81676 7 2 72840 7 3 96493 7 5 75581 7 6 97962 8 2 35448 8 3 48547 8 4 38631 8 5 82104 8 6 23747 8 7 36514 9 1 48937 9 2 11326 9 3 69303 9 4 82858 9 5 63680 9 6...
output:
597511
result:
ok 1 number(s): "597511"
Test #16:
score: 0
Accepted
time: 153ms
memory: 48540kb
input:
10000 100000 2188 6529 2 2188 7677 2 2188 7805 2 2188 9308 2 6529 7677 2 7805 9308 2 9599 3197 1 1786 3787 1 3578 3237 1 4859 8184 1 5300 3418 1 8450 499 1 8636 8041 1 8387 362 1 2902 1224 1 4847 1610 1 1619 3629 1 1694 5617 1 12 9337 1 4295 2005 1 6636 8226 1 9375 8605 1 9768 4222 1 2699 3741 1 537...
output:
12
result:
ok 1 number(s): "12"
Test #17:
score: 0
Accepted
time: 156ms
memory: 48592kb
input:
10000 100000 4562 1795 2 4562 2711 2 4562 3418 2 4562 5389 2 1795 2711 2 3418 5389 2 5748 3255 1 4941 6175 1 4685 7745 1 9064 5340 1 8299 8951 1 6060 4991 1 8897 6685 1 3518 4129 1 1106 6438 1 7695 3588 1 5920 5482 1 3070 9224 1 2582 5878 1 6686 8890 1 4017 4816 1 1282 4041 1 4601 436 1 2500 1638 1 ...
output:
12
result:
ok 1 number(s): "12"
Test #18:
score: 0
Accepted
time: 167ms
memory: 48620kb
input:
10000 100000 6937 2540 2 6937 2679 2 6937 6749 2 6937 7929 2 2540 2679 2 6749 7929 2 1897 3312 1 1744 4915 1 5791 8605 1 3268 6145 1 7651 4484 1 22 9483 1 9159 5330 1 8649 7897 1 9309 1651 1 543 5566 1 222 3688 1 4447 6479 1 1504 8771 1 9076 2126 1 7750 5054 1 3189 9477 1 3082 6651 1 2300 3183 1 315...
output:
12
result:
ok 1 number(s): "12"
Test #19:
score: -100
Wrong Answer
time: 12ms
memory: 40020kb
input:
10000 29992 1 2 1 9997 1 1 9998 1 1 2 3 1 9997 2 1 9998 2 1 3 4 1 9997 3 1 9998 3 1 4 5 1 9997 4 1 9998 4 1 5 6 1 9997 5 1 9998 5 1 6 7 1 9997 6 1 9998 6 1 7 8 1 9997 7 1 9998 7 1 8 9 1 9997 8 1 9998 8 1 9 10 1 9997 9 1 9998 9 1 10 11 1 9997 10 1 9998 10 1 11 12 1 9997 11 1 9998 11 1 12 13 1 9997 12...
output:
6
result:
wrong answer 1st numbers differ - expected: '100302', found: '6'