Submission #838365

#TimeUsernameProblemLanguageResultExecution timeMemory
838365mat_jurToll (BOI17_toll)C++17
0 / 100
181 ms524288 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;} auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";} #define debug(X) cerr << "["#X"]: " << X << '\n'; #else #define debug(X) ; #endif #define ll long long #define all(v) (v).begin(), (v).end() #define FOR(i,l,r) for(int i=(l);i<=(r);++i) #define ROF(i,r,l) for(int i=(r);i>=(l);--i) #define REP(i,n) FOR(i,0,(n)-1) #define ssize(x) int(x.size()) #define fi first #define se second int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int k, n, m, o; cin >> k >> n >> m >> o; vector<vector<pair<int, int>>> G(n); REP(i, m) { int a, b, t; cin >> a >> b >> t; G[a].push_back({b, t}); } constexpr int inf = 1e9; vector dp(n, vector(n, inf)); REP(j, n) { dp[j][j] = 0; ROF(i, n-1, 0) { for (auto w : G[i]) { dp[i][j] = min(dp[i][j], w.se+dp[w.fi][j]); } } } REP(i, o) { int a, b; cin >> a >> b; cout << (dp[a][b]==inf?-1:dp[a][b]) << '\n'; } return 0; }
#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...