QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#790435 | #7883. Takeout Delivering | aYi_7 | RE | 11ms | 51420kb | C++17 | 1.8kb | 2024-11-28 12:01:18 | 2024-11-28 12:01:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>>node[2000009];
int dis1[200009],dis2[300009];
const int INF=2e9+7;
signed main()///node是必须维护的;
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
int a,b,w;
scanf("%d%d%d",&a,&b,&w);
node[a].push_back(make_pair(b,w));
node[b].push_back(make_pair(a,w));
}
priority_queue<pair<int,int>,vector<pair<int,int> >,greater < pair <int,int> > > qq;
qq.push(make_pair(0,1));
for(int i=1;i<=n;i++)
{
dis1[i]=INF;
dis2[i]=INF;
}
dis1[1]=0;
dis2[n]=0;
while(!qq.empty())
{
auto [val,u]=qq.top();
qq.pop();
for(int i=0;i<node[u].size();i++)
{
auto[a,b]=node[u][i];
int mx=max(val,b);
if(mx<dis1[a])
{
dis1[a]=mx;
qq.push(make_pair(dis1[a],a));
}
}
}
qq.push(make_pair(0,n));
while(!qq.empty())
{
auto [val,u]=qq.top();
qq.pop();
for(int i=0;i<node[u].size();i++)
{
auto[a,b]=node[u][i];
int mx=max(val,b);
if(mx<dis2[a])
{
dis2[a]=mx;
qq.push(make_pair(dis2[a],a));
}
}
}
int ans=INF;
for(int i=1;i<=n;i++)
{
for(auto [x,w]:node[i])
{
int a=i,b=x;
int ax=dis1[a],bx=dis2[b];
if(w>=max(ax,bx))
{
ans=min(ans,w+max(ax,bx));
}
ax=dis1[b],bx=dis2[a];
if(w>=max(ax,bx))
{
ans=min(ans,w+max(ax,bx));
}
}
}
printf("%d\n",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 11ms
memory: 51420kb
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
Runtime Error
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 ...