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 ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll k,n,m,O;
cin>>k>>n>>m>>O;
vector<pair<ll,ll>>adj[n];
for(ll i=1;i<=m;i++){
ll a,b,t;
cin>>a>>b>>t;
adj[a].pb({b,t});
}
ll dp[n];
for(ll i=1;i<=O;i++){
ll a,b;
cin>>a>>b;
fill(dp,dp+b+1,1e18);
dp[a]=0;
for(ll j=a;j<b;j++){
for(auto [y,t]:adj[j]){
dp[y]=min(dp[y],dp[j]+t);
}
}
if(dp[b]==1e18){
cout<<-1<<"\n";
}
else{
cout<<dp[b]<<"\n";
}
}
}
# | 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... |