QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#199851#7343. Bicycle RaceVengeful_Spirit#WA 2ms14452kbC++142.4kb2023-10-04 14:21:162023-10-04 14:21:16

Judging History

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

  • [2023-10-04 14:21:16]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:14452kb
  • [2023-10-04 14:21:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=200001;
int ind[N];
pair<int,int>tag[N];
vector<pair<int,int>>e[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});
}
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 solve(int x){
    if(res[x].size()<=1)return -1;
    int max_z,max_y,max_v=-1;
    for(auto [y,z,val]:res[x]){
        if(val>max_v){
            max_y=y;
            max_z=z;
            max_v=val;
        }
    }
    pair<int,int> fix_y={-1,-1},fix_z={-1,-1};
    int libre=-1;
    for(auto [y,z,val]:res[x]){
        if(max_y==y){
            if(max_z!=z){
                fix_y=max(fix_y,{val,z});
            }
        }
        else if(max_z==z){
            if(max_y!=y){
                fix_z=max(fix_z,{val,y});
            }
        }
        else if(max_z==y){
            if(max_y!=z){
                fix_z=max(fix_z,{val,z});
            }
        }
        else if(max_y==z){
            if(max_z!=y){
                fix_y=max(fix_y,{val,y});
            }
        }
        else {
       //     cout<<"safe "<<y<<" "<<z<<endl;
            libre=max(libre,val);}
    }
   // cout<<x<<" "<<max_y<<" "<<max_z<<' '<<fix_y.second<<" "<<fix_z.second<<" "<<libre<<endl;
    if(libre==-1&&(fix_y.first==-1||fix_z.first==-1))return -1;
    return max(max_v+libre,fix_y.first+fix_z.first);
}
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});
    }
    for(int i=1;i<=n;i++){
        dfs2(i);
    }
    int ans=-1;
    for(int i=1;i<=n;i++){
        ans=max(ans,solve(i));
    }
    printf("%d\n",ans);

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 14452kb

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: 13176kb

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: 14168kb

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: -100
Wrong Answer
time: 2ms
memory: 13696kb

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:

47

result:

wrong answer 1st numbers differ - expected: '45', found: '47'