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>
#define int long long
#define pb push_back
using namespace std;
vector<pair<int,int>>v[100100];
const int inf=1e18;
int dp[100][100][1000];
int f(int x,int y,int k)
{
if(k<0)
return inf;
if(x==y)
{
return 0;
}
if(dp[x][y][k])
return dp[x][y][k];
int mn=1e18;
for(int i=0;i<v[x].size();i++)
{
mn=min(mn,v[x][i].second+f(v[x][i].first,y,k-1));
}
return dp[x][y][k]=mn;
}
signed main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++)
{
int c,o,w;
cin>>c>>o>>w;
v[c].pb({o,w});
}
int q,k;
cin>>k>>q;
while(q--)
{
int x,y;
cin>>x>>y;
if(f(x,y,k)<=1e15)
cout<<f(x,y,k)<<endl;
else cout<<-1<<endl;
}
}
Compilation message (stderr)
Main.cpp: In function 'long long int f(long long int, long long int, long long int)':
Main.cpp:20:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i=0;i<v[x].size();i++)
| ~^~~~~~~~~~~~
# | 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... |