This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
long long cost[2005];
long long ti[2005];
vector<pair<int,pair<int,int>>> adj[2005];
signed main(){
int n,m;
cin>>n>>m;
for(int i = 0;i<m;i++){
int a,b,c,d;
cin>>a>>b>>c>>d;
adj[a].push_back({b,{c,d}});
adj[b].push_back({a,{c,d}});
}
for(int i = 2;i<=n;i++){
cost[i] = 1e15;
ti[i] = 1e15;
}
priority_queue<pair<int,pair<int,int>>> q;
q.push({0,{0,1}});
while(!q.empty()){
int no = q.top().second.second;
int fi = q.top().second.first;
int se = -q.top().first;
q.pop();
cost[no] = min(cost[no],fi*se);
if(ti[no]<fi)continue;
ti[no] = fi;
for(auto j:adj[no]){
if(fi+j.second.first>4000005)continue;
q.push({-(se+j.second.second),{fi+j.second.first,j.first}});
}
}
for(int i = 2;i<=n;i++){
long long ans = cost[i];
if(ans==1e15){
cout<<"-1"<<endl;
}
else cout<<ans<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |