QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278278#7883. Takeout DeliveringkokomiisbestWA 275ms41776kbC++171.9kb2023-12-07 14:33:452023-12-07 14:33:46

Judging History

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

  • [2023-12-07 14:33:46]
  • 评测
  • 测评结果:WA
  • 用时:275ms
  • 内存:41776kb
  • [2023-12-07 14:33:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
const int N = 3e5+10,M = 1e6+10;
int h[N],e[M],ne[M],w[M],idx;
int max1[N],max2[N],dist[N];//dist?\xbb\xa4?\xc3\xe6·\xbe\xb6\xb5\xc4\xd7\xeeС?\xbe\xb1·
int dist1[N];
int ans[N];
bool st[N];

void add(int a,int b,int c){
    w[idx]=c;
    e[idx]=b;
    ne[idx]=h[a];
    h[a]=idx++;
}

//并查集
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> MST;
vector<edge> e1;
int main(){
	memset(h,-1,sizeof h);
    cin>>n>>m;
    int ans1=0x3f3f3f3f;
    while(m--){
        int a,b,c;
        cin>>a>>b>>c;
        e1.push_back({a,b,c});
        // add(a,b,c),add(b,a,c);
    }
    //最小生成树
    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(int i=2;i<=n-1;i++){
// //		cout<<dist[i]<<"---"<<dist1[i]<<endl;
// 		ans=max(ans,(ll)dist[i]+(ll)dist1[i]);
// 	}
    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;
    
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 14432kb

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: 275ms
memory: 41776kb

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'