이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |