QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#277702#7883. Takeout Delivering1677118046#WA 159ms42604kbC++171.8kb2023-12-06 21:39:552023-12-06 21:39:55

Judging History

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

  • [2023-12-06 21:39:55]
  • 评测
  • 测评结果:WA
  • 用时:159ms
  • 内存:42604kb
  • [2023-12-06 21:39:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nn=3e5+10;
vector<pair<ll,ll>>XX[nn];
ll dis1[nn];//维护从1到每一个点的最小值 
ll dis2[nn];//维护从n开始到每一个点的最小值 
ll vis1[nn];//判断是否更新
ll vis2[nn]; 
ll n,m;
void bfs1(int x){
	deque<int>X;
	X.push_back(x);
	memset(dis1,0x3f,sizeof dis1);
	dis1[x]=0;
	while(!X.empty()){
		int id=X.front();
		X.pop_front();
		if(vis1[id])continue;
		vis1[id]++;
		for(auto ii:XX[id]){
			int ne=ii.first;
			ll val=ii.second;
			val=max(val,dis1[id]);
			if(val<dis1[ne]){
				dis1[ne]=val;
				X.push_back(ne);
			}
		}
	}
}
void bfs2(int x){
	deque<int>X;
	X.push_back(x);
	memset(dis2,0x3f,sizeof dis2);
	dis2[x]=0;
	while(!X.empty()){
		int id=X.front();
		X.pop_front();
		if(vis2[id])continue;
		vis2[id]++;
		for(auto ii:XX[id]){
			int ne=ii.first;
			ll val=ii.second;
			val=max(val,dis2[id]);
			if(val<dis2[ne]){
				dis2[ne]=val;
				X.push_back(ne);
			}
		}
	}
}
struct node{
	ll u,v,w;
}A[nn];
void solve(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;ll w;
		cin>>u>>v>>w;
		A[i].u=u;
		A[i].v=v;
		A[i].w=w;
		XX[u].push_back({v,w});
		XX[v].push_back({u,w});
	}
	bfs1(1);
	bfs2(n);
	ll an=1e18+10;
	vector<ll>C;
	for(int i=1;i<=m;i++){
		C.push_back(A[i].w);
		//一个u,一个v 
		C.push_back(dis1[A[i].u]);
		C.push_back(dis2[A[i].v]);
		sort(C.begin(),C.end());
		an=min(C[2]+C[1],an);
		C.clear();
		C.push_back(A[i].w);
		//一个u,一个v 
		C.push_back(dis2[A[i].u]);
		C.push_back(dis1[A[i].v]);
		sort(C.begin(),C.end());
		an=min(C[2]+C[1],an);
		C.clear();
	}
	cout<<an<<"\n";
	
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	solve();
}

详细

Test #1:

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

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: 159ms
memory: 42604kb

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:

1356916107

result:

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