QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276454#7883. Takeout DeliveringkokomiisbestWA 187ms20740kbC++142.4kb2023-12-05 21:25:512023-12-05 21:25:51

Judging History

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

  • [2023-12-05 21:25:51]
  • 评测
  • 测评结果:WA
  • 用时:187ms
  • 内存:20740kb
  • [2023-12-05 21:25:51]
  • 提交

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];
long long ans1;
void add(int a,int b,int c){
    w[idx]=c;
    e[idx]=b;
    ne[idx]=h[a];
    h[a]=idx++;
    if((a==1&&b==n)||(a==n||b==1)) ans1=c;
}
typedef pair<int, int> PII;
void dij1(){//\xc7\xf3\xd7\xee\xb6\xccƿ\xbe\xb1·
    memset(dist,0x3f,sizeof dist);
    memset(st,false,sizeof st);
    dist[1]=0;
//    st[1]=true;
    priority_queue<PII, vector<PII>, greater<PII>> pq; 
    pq.push({0,1});
    while(pq.size()){
        PII k=pq.top();
        pq.pop();
        int ver=k.second,distance=k.first;
        if(st[ver]) continue;
        st[ver]=true;

        for(int i=h[ver];i!=-1;i=ne[i]){
            int j=e[i];
//            if(w[i]>dist[j]){
//                dist[j]=w[i];
//                cout<<j<<" "<<dist[j]<<endl;
//                pq.push({dist[j],j});
//            }
			int val=max(dist[ver],w[i]);
//			cout<<j<<" "<<val<<endl;
			if(val<dist[j]){
				dist[j]=val;
//				cout<<j<<" "<<dist[j]<<endl;
				pq.push({dist[j],j});
			}
        }
    }
}

void dij2(){
	memset(dist1,0x3f,sizeof dist1);
    memset(st,false,sizeof st);
    dist1[n]=0;
    priority_queue<PII, vector<PII>, greater<PII>> pq; 
    pq.push({0,n});
    while(pq.size()){
        PII k=pq.top();
        pq.pop();
        int ver=k.second,distance=k.first;
        if(st[ver]) continue;
        st[ver]=true;

        for(int i=h[ver];i!=-1;i=ne[i]){
            int j=e[i];
//            if(w[i]>dist[j]){
//                dist[j]=w[i];
//                cout<<j<<" "<<dist[j]<<endl;
//                pq.push({dist[j],j});
//            }
			int val=max(dist1[ver],w[i]);
//			cout<<j<<" "<<val<<endl;
			if(val<dist1[j]){
				dist1[j]=val;
//				cout<<j<<" "<<dist[j]<<endl;
				pq.push({dist1[j],j});
			}
        }
    }
} 


int main(){
	memset(h,-1,sizeof h);
    cin>>n>>m;
    while(m--){
        int a,b,c;
        cin>>a>>b>>c;
        add(a,b,c),add(b,a,c);
    }
    dij1();
    dij2();
    ll ans=0;
	for(int i=2;i<=n-1;i++){
//		cout<<dist[i]<<"---"<<dist1[i]<<endl;
		ans=max(ans,(ll)dist[i]+(ll)dist1[i]);
	}
	ans1=min(ans1,ans);
	cout<<ans1<<endl;
    
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 13184kb

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: 187ms
memory: 20740kb

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:

966659373

result:

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