QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#274116 | #7883. Takeout Delivering | youthpaul | WA | 71ms | 18300kb | C++17 | 1.8kb | 2023-12-03 10:48:32 | 2023-12-03 10:48:32 |
Judging History
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 = INF;
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: 1ms
memory: 5476kb
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: 71ms
memory: 18300kb
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'