제출 #557551

#제출 시각아이디문제언어결과실행 시간메모리
557551fatemetmhrToll (BOI17_toll)C++17
49 / 100
3024 ms17612 KiB
// `Be name khoda` // #include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define all(x) x.begin(), x.end() #define fi first #define se second const int maxn5 = 2e5 + 10; const int inf = 1e9; int dis[maxn5], prec[maxn5]; vector <pair<int, int>> jda[maxn5], adj[maxn5]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int k, n, m, q; cin >> k >> n >> m >> q; for(int i = 0; i < m; i++){ int a, b, t; cin >> a >> b >> t; jda[b].pb({a, t}); adj[a].pb({b, t}); } fill(prec, prec + n + 5, inf); prec[0] = 0; for(int i = 0; i < n; i++) for(auto [u, t] : adj[i]) prec[u] = min(prec[u], prec[i] + t); for(int i = 0; i < n; i++) if(prec[i] == inf) prec[i] = -1; for(int i = 0; i < q; i++){ int a, b; cin >> a >> b; if(a == 0){ cout << prec[b] << '\n'; continue; } fill(dis, dis + n + 4, inf); dis[b] = 0; for(int i = b; i > a; i--){ for(auto [u, t] : jda[i]) dis[u] = min(dis[u], dis[i] + t); } if(dis[a] == inf) dis[a] = -1; cout << dis[a] << '\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...