This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
بسم الله الرحمن الرحيم
Author:
(:Muhammad Aneeq:)
*/
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
map<pair<int,int>,int>d;
int const N=5e4+10;
vector<pair<int,int>>nei[N]={};
int dist[N]={};
bool vis[N]={};
int ans=0;
void dfs(int n,int v,int cost=0)
{
if (n>v)
return ;
if (n==v)
{
ans=min(ans,cost);
return;
}
if (cost>ans)
return;
for (auto [j,w]:nei[n])
dfs(j,v,cost+w);
}
inline void solve()
{
int n,m,k,o;
cin>>k>>n>>m>>o;
while (m--)
{
int a,b,t;
cin>>a>>b>>t;
nei[a].push_back({b,t});
}
vector<pair<int,int>>ord;
while (o--)
{
int x,y;
cin>>x>>y;
ans=1e9+10;
dfs(x,y);
cout<<(ans==1e9+10?-1:ans)<<endl;
}
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
solve();
}
# | 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... |