QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#274118#7883. Takeout DeliveringyouthpaulWA 63ms16804kbC++171.8kb2023-12-03 10:57:522023-12-03 10:57:52

Judging History

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

  • [2023-12-03 10:57:52]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:16804kb
  • [2023-12-03 10:57:52]
  • 提交

answer

#include<bits/stdc++.h>
#define fore(i,l,r)	for(int i=(int)(l);i<(int)(r);++i)
#define fi first
#define se second
#define endl '\n' 
#define ull unsigned long long

const int INF=0x3f3f3f3f;
const long long INFLL=0x3f3f3f3f3f3f3f3fLL;

typedef long long ll;

const int N=300050;
const int M=1000050;

struct Edge{
	int to;
	int next;
	int w;
}edge[M<<1];

int cnt;
int head[N];
std::pair<int,int> dis1[N];
std::pair<int,int> dis2[N];
int n,m;

struct Node{
	int u;
	int w;
	int id;
	
	bool operator < (const Node& x) const {
		return x.w < w;
	}
};

inline void addedge(int u,int v,int w){
	edge[++cnt] = {v,head[u],w};
	head[u] = cnt;
	edge[++cnt] = {u,head[v],w};
	head[v] = cnt;
}

void Dijkstra(int s,std::pair<int,int> dis[]){
	fore(i,1,n+1){
		dis[i].fi = 2e9+5;
		dis[i].se = 0;
	}
	dis[s].fi = dis[s].se = 0;
	std::priority_queue<Node> q;
	q.push({s,0,0});
	while(!q.empty()){
		auto [u,d,ID] = q.top();
		q.pop();
		for(int i=head[u];i;i=edge[i].next){
			int v = edge[i].to , w = edge[i].w , id = i;
			if(w < d){
				w = d;
				id = ID;
			}
			if(dis[v].fi > w){
				dis[v].fi = w;
				dis[v].se = id;
				q.push({v,w,id});
			}
		}
	}
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    /* HeFei J */
    
    std::cin>>n>>m;
    fore(i,0,m){
    	int u,v,w;
    	std::cin>>u>>v>>w;
    	addedge(u,v,w);
    }
    Dijkstra(1,dis1);
    Dijkstra(n,dis2);
    int ans = INF;
    fore(u,1,n+1){
    	for(int i=head[u];i;i=edge[i].next){
    		int v = edge[i].to, w = edge[i].w;
    		if(dis1[u].fi > w || dis2[v].fi > w)	continue;
    		if(dis1[u].se == i || dis2[v].se == i)	continue;
    		ans = std::min(ans,w + std::max(dis1[u].fi,dis2[v].fi));
    	}
    }
    std::cout<<ans;
	return 0; 
}











詳細信息

Test #1:

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

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: 63ms
memory: 16804kb

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'