제출 #1128798

#제출 시각아이디문제언어결과실행 시간메모리
1128798MuhammetToll (BOI17_toll)C++20
56 / 100
2635 ms4772 KiB
#include <bits/stdc++.h> using namespace std; #define SZ(s) (int)s.size() #define ff first #define ss second int k, n, m, o; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> k >> n >> m >> o; vector <vector <pair<int,int>>> v(n); for(int i = 1; i <= m; i++){ int u1, u2, s; cin >> u1 >> u2 >> s; v[u1].push_back({u2,s}); } bool tr = 0; vector <int> dis1(n, 1e9); 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] == 1e9 ? -1 : dis1[b]) << '\n'; continue; } vector <int> dis(n, 1e9); dis[a] = 0; for(int i = a; i < n; i++){ for(auto j : v[i]){ dis[j.ff] = min(dis[j.ff], dis[i] + j.ss); } } cout << (dis[b] == 1e9 ? -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...