QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#278329#7883. Takeout DeliveringkokomiisbestWA 117ms37752kbC++141.6kb2023-12-07 14:57:572023-12-07 14:57:58

Judging History

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

  • [2023-12-07 14:57:58]
  • 评测
  • 测评结果:WA
  • 用时:117ms
  • 内存:37752kb
  • [2023-12-07 14:57:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
const int N = 3e5+10,M = 1e6+10;
int dist[N];
int dist1[N];



//\xb2\xa2\xb2鼯
int pre[N];
void init(){
    for(int i=1;i<=n;i++) pre[i]=i;
}
int find(int x){
    if(pre[x]!=x) pre[x]=find(pre[x]);
    return pre[x];
}
bool merge(int x,int y){
    int px=find(x),py=find(y);
    if(px!=py){
        pre[px]=py;
        return 1;
    }
    return 0;
}
struct node{int x,w;};
vector<node> mp[N];
void dfs(int x,int fa,int *v){
    for(auto it:mp[x]){
        if(it.x==fa) continue;
        v[it.x]=max(v[x],it.w);
        dfs(it.x,x,v);
    }
}

struct edge{
    int a,b,c;
};

vector<edge> e1;
int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
    cin>>n>>m;
    int ans1=0x3f3f3f3f;
    while(m--){
        int a,b,c;
        cin>>a>>b>>c;
        e1.push_back({a,b,c});
    }
    //\xd7\xeeС\xc9\xfa\xb3\xc9\xca\xf7
    sort(e1.begin(),e1.end(),[&](edge x,edge y){
        return x.c<y.c;
    });
    init();
    for(auto it:e1){
        if(merge(it.a,it.b)){
            mp[it.a].push_back({it.b,it.c});
            mp[it.b].push_back({it.a,it.c});
        }
    }
    dfs(1,0,dist);
    dfs(n,0,dist1);
    int ans=0x3f3f3f3f;

    for(auto x:e1){
        int a=x.a,b=x.b,c=x.c;
        if(a>b) swap(a,b);
        if(a==1&&b==n) ans=min(ans,c);
        if(dist1[a]<=c&&dist[b]<=c) ans=min(ans,c+max(dist1[a],dist[b]));
        if(dist1[b]<=c&&dist[a]<=c) ans=min(ans,c+max(dist1[b],dist[a]));
    }
	cout<<ans<<endl;
//	cout<<ans<<" "<<ans1<<endl;
    
}

详细

Test #1:

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

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

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:

1061109567

result:

wrong answer 1st numbers differ - expected: '1999991697', found: '1061109567'