Submission #864527

#TimeUsernameProblemLanguageResultExecution timeMemory
864527maks007Toll (BOI17_toll)C++14
10 / 100
118 ms6844 KiB
// Bismi ALlah #include "bits/stdc++.h" using namespace std; #define int long long signed main () { int n, m, k, query; cin >> k >> n >> m >> query; vector<pair <int,int>> g[n]; for(int i = 0; i < m; i ++) { int u, v; cin >> u >> v; int w; cin >> w; g[u].push_back({v, w}); } int dp[n][k]; for(int i = 0; i < n; i ++) { for(int j = 0; j < k; j ++) dp[i][j] = LLONG_MAX; } for(int j = 0; j < k; j ++) { dp[j][j] = 0; for(int i = 0; i < n; i ++) { if(dp[i][j] != LLONG_MAX) { for(auto [u, w] : g[i]) { dp[u][j] = min(dp[u][j], dp[i][j] + w); } } } } while(query --) { int a, b; cin >> a >> b; int mn = LLONG_MAX; for(int i = 0; i < k; i ++) { if(dp[b][i] == LLONG_MAX || dp[a][i] == LLONG_MAX) continue; mn = min(mn, dp[b][i] - dp[a][i]); } if(mn == LLONG_MAX) cout << -1 << "\n"; else cout << mn << "\n"; } return 0; }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:27:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |     for(auto [u, w] : g[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...
#Verdict Execution timeMemoryGrader output
Fetching results...