QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#601229 | #7883. Takeout Delivering | lamp_ | TL | 0ms | 13992kb | C++17 | 1.6kb | 2024-09-29 21:34:33 | 2024-09-29 21:34:34 |
Judging History
answer
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(x) (cout<<(#x)<<':'<<(x)<<'\n')
#define endl '\n'
#define lowbit(x) x & (-x)
#define mst(a) memset(a,0,sizeof a)
#define y second
#define x first
using namespace std;
typedef long long ll; typedef pair<int,int> PII; typedef unsigned long long ull;
const int N = 3e5+10,P = 131,INF = 0x3f3f3f3f;
vector<PII> ver[N];
PII ans[N];
bool st[N];
int res[N];
void insert(int idx,int idx_,int v){
vector<int> t={v,ans[idx_].first,ans[idx_].second};
sort(t.begin(),t.end());
ans[idx]={t[2],t[1]};
}
int sum(PII a){
return a.first+a.second;
}
void bfs(){
queue<int> q;
q.push(1);
while(q.size()){
int u = q.front();
//cout<<u<<" "<<ans[u].first<<" "<<ans[u].second<<" "<<endl;
st[u]=false;
q.pop();
for(PII it:ver[u]){
//cout<<u<<endl;
int v=it.first,val=it.second;
PII pre = ans[v];
insert(v,u,val);
PII cur = ans[v];
if(res[v]==INF || cur.second==0 || (sum(cur)<sum(pre))){
if(!st[v]) st[v]=true,q.push(v);
res[v]=min(res[v],sum(cur));
}else ans[v]=pre;
}
}
}
void solve(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++) res[i]=0x3f3f3f3f;
while(m--){
int a,b,c;
cin>>a>>b>>c;
ver[a].push_back({b,c});
ver[b].push_back({a,c});
}
bfs();
cout<<res[n]<<"\n";
}
int main(){
IOS;
int T = 1;
//cin>>T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 13992kb
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
Time Limit Exceeded
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 ...