Submission #546912

#TimeUsernameProblemLanguageResultExecution timeMemory
546912ala2Autobus (COCI22_autobus)C++14
30 / 70
1090 ms31164 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...