Submission #924467

#TimeUsernameProblemLanguageResultExecution timeMemory
924467Faisal_SaqibToll (BOI17_toll)C++17
8 / 100
3069 ms4540 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; const int N=5e4; vector<pair<int,int>> ma[N]; int dist[N]; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); int k,n,m,q; cin>>k>>n>>m>>q; for(int j=0;j<m;j++) { int a,b,t; cin>>a>>b>>t; ma[a].push_back({b,t}); } priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq; for(int lp=0;lp<q;lp++) { int x,y; cin>>x>>y; for(int i=0;i<n;i++) dist[i]=1e9; dist[x]=0; int ans=-1; pq.push({dist[x],x}); while(pq.size()) { auto it=pq.top(); pq.pop(); if(it.second==y) { ans=it.first; break; } if(dist[it.second]==it.first) { for(auto [v,w]:ma[it.second]) { if(dist[v]>(it.first+w) and v<=y) { dist[v]=it.first+w; pq.push({dist[v],v}); } } } } while(pq.size()) pq.pop(); cout<<ans<<'\n'; } return 0; }
#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...