QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#200540#7343. Bicycle RaceVengeful_Spirit#ML 5ms9984kbC++145.0kb2023-10-04 17:25:052023-10-04 17:25:06

Judging History

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

  • [2023-10-04 17:25:06]
  • 评测
  • 测评结果:ML
  • 用时:5ms
  • 内存:9984kb
  • [2023-10-04 17:25:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=100005,INF=1e9;
int ind[N];
pair<int,int>tag[N];
vector<pair<int,int>>e[N];
vector<pair<int, tuple<int,int,int>>> ring;
vector<int> res[N];
// vector<tuple<int,int,int>>res[N];
int ord(int x,int v){
    return (ind[x]>ind[v]||(ind[x]==ind[v]&&x>v));
}
void report(int x,int y,int z,int val){
  //  cout<<x<<" "<<y<<" "<<z<<" "<<val<<endl;
    // if(y>z)res[x].push_back({y,z,val});
    // else res[x].push_back({z,y,val});
    // if(x>z)res[y].push_back({x,z,val});
    // else res[y].push_back({z,x,val});
    // if(x>y)res[z].push_back({x,y,val});
    // else res[z].push_back({y,x,val});
    ring.push_back({-val, {x, y, z}});
}
void dfs2(int x){
    for(auto [v,val]:e[x]){
        if(!ord(x,v))continue;
        tag[v]={x,val};
    }
    for(auto [v,val]:e[x]){
        if(!ord(x,v))continue;
        for(auto [v2,val2]:e[v]){
            if(!ord(v,v2))continue;
            if(tag[v2].first==x){
                report(x,v,v2,tag[v2].second+val+val2);
            }
        }
    }
}
int cnt[N];
int solve(int x) {
    vector<tuple<int,int,int>> ri;
    int now=0;
    for(auto &id : res[x]) {
        auto [xx, yy, zz] = ring[id].second;
        if(yy == x) swap(xx, yy);
        if(zz == x) swap(zz, xx);
        if(cnt[yy] < 3 || cnt[zz] < 3) {
            ++cnt[yy];
            ++cnt[zz];
            ri.push_back({yy, zz, -ring[id].first});
            ++now;
        }
        if(now >= 6) break;
    }
    int ans = -1;
    for(int i = 0; i < ri.size(); ++i) {
        for(int j = i+1; j < ri.size(); ++j) {
            auto [xi, yi, vali] = ri[i];
            auto [xj, yj, valj] = ri[j];
            if(xi!=xj&&yi!=xj&&xi!=yj&&yi!=yj)
                ans=max(ans, vali+valj);
        }
    }
    for(auto [xx, yy, val] : ri) --cnt[xx], --cnt[yy];
    return ans;
}
// int solve(int x){
//     if(res[x].size()<=1)return -1;
//     int max_v=-1;
//     vector<pair<int,int>>s;
//     for(auto [y,z,val]:res[x]){
//         if(val>max_v){
//             max_v=val;
//         }
//     }
//     int ans=-1;
//     for(auto [y,z,val]:res[x]){
//         if(val==max_v){
//             s.push_back({y,z});
//         }
//     }
//     for(auto [max_y,max_z]:s){
//         pair<int,int> fix_y={-INF,-1},sfix_y={-INF,-1},fix_z={-INF,-1},sfix_z={-INF,-1};
//         int libre=-1;
//         for(auto [y,z,val]:res[x]){
//             if(max_y==y){
//                 if(max_z!=z){
//                     if(val>=fix_y.first){
//                         sfix_y=fix_y;
//                         fix_y={val,z};
//                     }
//                     else sfix_y=max(sfix_y,{val,z});
//                 }
//             }
//             else if(max_z==z){
//                 if(max_y!=y){
//                     if(val>=fix_z.first){
//                         sfix_z=fix_z;
//                         fix_z={val,y};
//                     }
//                     else sfix_z=max(sfix_z,{val,y});
//                 }
//             }
//             else if(max_z==y){
//                 if(max_y!=z){
//                     if(val>=fix_z.first){
//                         sfix_z=fix_z;
//                         fix_z={val,z};
//                     }
//                     else sfix_z=max(sfix_z,{val,z});
//                 }
//             }
//             else if(max_y==z){
//                 if(max_z!=y){
//                     if(val>=fix_y.first){
//                         sfix_y=fix_y;
//                         fix_y={val,y};
//                     }
//                     else sfix_y=max(sfix_y,{val,y});
//                 }
//             }
//             else {
//         //     cout<<"safe "<<y<<" "<<z<<endl;
//                 libre=max(libre,val);}
//         }
//     // cout<<x<<" "<<max_v<<" "<<max_y<<" "<<max_z<<' '<<fix_y.second<<" "<<fix_z.second<<" "<<sfix_y.second<<" "<<sfix_z.second<<" "<<libre<<endl;
//         if(libre!=-1)ans=max(ans,max_v+libre);
//         if(fix_y.second!=fix_z.second)ans=max(ans,fix_y.first+fix_z.first);
//         if(sfix_y.second!=fix_z.second)ans=max(ans,sfix_y.first+fix_z.first);
//         if(fix_y.second!=sfix_z.second)ans=max(ans,fix_y.first+sfix_z.first);
//         if(ans==max_v*2)return ans;
//     }
//   /////  cout<<ans<<endl;
//     return ans;
// }
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        e[x].push_back({y,z});
        e[y].push_back({x,z});
        ind[x]++;
        ind[y]++;
    }
    for(int i=1;i<=n;i++){
        dfs2(i);
    }
    sort(ring.begin(), ring.end());
    int now = 0;
    for(auto &[val, o] : ring) {
        auto [x, y, z] = o;
        res[x].push_back(now);
        res[y].push_back(now);
        res[z].push_back(now++);
    }
    int ans=-1;
    for(int i=1;i<=n;i++){
        ans=max(ans,solve(i));
    }
    printf("%d\n",ans);

}

詳細信息

Test #1:

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

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: 1ms
memory: 8424kb

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: 0ms
memory: 9312kb

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: 2ms
memory: 9372kb

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: 0ms
memory: 9152kb

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: 2ms
memory: 9832kb

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: 0ms
memory: 8824kb

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: 3ms
memory: 9984kb

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: 0ms
memory: 8768kb

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: 3ms
memory: 9060kb

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: 4ms
memory: 8708kb

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: 5ms
memory: 9376kb

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: 2ms
memory: 9624kb

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: -100
Memory Limit Exceeded

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: