Submission #1128935

#TimeUsernameProblemLanguageResultExecution timeMemory
1128935MuhammetToll (BOI17_toll)C++20
56 / 100
1317 ms6776 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define SZ(s) (int)s.size() #define ff first #define ss second const int inf = 1e9+7; ll k, n, m, o; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> k >> n >> m >> o; vector <vector <pair<int,ll>>> v(n); for(int i = 1; i <= m; i++){ int u1, u2; ll s; cin >> u1 >> u2 >> s; v[u1].push_back({u2,s}); } bool tr = 0; vector <ll> dis1(n, inf); if(o > 3000 and k != 1){ dis1[0] = 0; for(int i = 0; i < n; i++){ for(auto j : v[i]){ dis1[j.ff] = min(dis1[j.ff], dis1[i] + j.ss); } } tr = 1; } while(o--){ int a, b; cin >> a >> b; if(tr){ cout << (dis1[b] == inf ? -1 : dis1[b]) << '\n'; continue; } vector <ll> dis(n, inf); dis[a] = 0; for(int i = a; i <= b; i++){ for(auto j : v[i]){ dis[j.ff] = min(dis[j.ff], dis[i] + j.ss); } } cout << (dis[b] == inf ? -1 : dis[b]) << '\n'; } }
#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...