QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276033#7883. Takeout DeliveringkokomiisbestWA 190ms19984kbC++174.2kb2023-12-05 15:06:542023-12-05 15:06:55

Judging History

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

  • [2023-12-05 15:06:55]
  • 评测
  • 测评结果:WA
  • 用时:190ms
  • 内存:19984kb
  • [2023-12-05 15:06:54]
  • 提交

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++;
}
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});
			}
        }
    }
} 

//void dij2(){
//    
//    priority_queue<PII, vector<PII>, greater<PII>> pq; 
//    memset(ans,0x3f,sizeof ans);
//    memset(st,false,sizeof st);
//	ans[1]=0;
//    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;i=ne[i]){
//            int j=e[i];
//            if(w[i]>=max1[ver]){
//                max2[j]=max1[ver];
//                max1[j]=w[i];
////                if(dist[j]<max2[j]){
////                    max2[j]=dist[j];
////                }
////                if(max1[j]+max2[j]<ans[j]){
////                    ans[j]=max1[j]+max2[j];
////                    pq.push({ans[j],j});
////                }
//            }else if(w[i]>=max2[ver]){
//                max2[j]=w[i];
//                max1[j]=max1[ver];
////                if(dist[j]<max1[j]){
////                    max1[j]=dist[j];
////                }
////                if(max1[j]+max2[j]<ans[j]){
////                    ans[j]=max1[j]+max2[j];
////                    pq.push({ans[j],j});
////                }
//            }else{
//                max1[j]=max1[ver],max2[j]=max2[ver];
////                if(max1[j]+max2[j]<ans[j]){
////                    ans[j]=max1[j]+max2[j];
////                    pq.push({ans[j],j});
////                }
//            }
//            if(w[i]>=dist[j]){
//            	max1[j]=w[i],max2[j]=dist[j];
//			}else if(w[i]>=max2[i]{
//				max1[j]
//			}
//            if(max1[j]+max2[j]<ans[j]){
//            	if(j==4) cout<<"--"<<max1[j]<<" "<<max2[j]<<endl;
//            	ans[j]=max1[j]+max2[j];
//            	cout<<j<<" "<<ans[j]<<endl;
//            	pq.push({ans[j],j});
//			}
//            
//            
//        }
////        cout<<max1[1]<<"---"<<max2[1]<<endl;
//    }
//}
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();
    int ans=0x3f;
	for(int i=2;i<=n-1;i++){
//		cout<<dist[i]<<"---"<<dist1[i]<<endl;
		ans=min(ans,dist[i]+dist1[i]);
	}
	cout<<ans<<endl;
    
}

详细

Test #1:

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

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: 190ms
memory: 19984kb

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:

63

result:

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