Submission #720257

#TimeUsernameProblemLanguageResultExecution timeMemory
720257Ahmed57Ceste (COCI17_ceste)C++14
160 / 160
541 ms25272 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...