Submission #864539

#TimeUsernameProblemLanguageResultExecution timeMemory
864539iskhakkutbilimToll (BOI17_toll)C++17
39 / 100
1924 ms6752 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define all(a) a.begin(), a.end() const int N = 5e4; const int mod = 1e17; vector< pair<int, int> > g[N]; int k, n, m, q; main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> k >> n >> m >> q; vector<int> dis(n, mod); for(int i = 0;i < m; i++){ int a, b, w; cin >> a >> b >> w; dis[b] = min(dis[b], w); g[a].push_back({b, w}); } vector<pair<int, int> > Q; int z = 0; for(int i = 0;i < q; i++){ int a, b; cin >> a >> b; z+= (a == 0); Q.push_back({a, b}); } if(z == q){ for(auto [a, b] : Q){ if(a == b){ cout << 0 << '\n'; continue; } if(dis[b] >= mod or a != 0) cout << "-1\n"; else cout << dis[b] << '\n'; } return 0; } for(auto [a, b] : Q){ if(a == b){ cout << 0 << '\n'; continue; } for(int i = 1;i <= n; i++) dis[i] = mod; dis[a] = 0; for(int i = a; i < n; i++){ for(auto [to, w] : g[i]){ if(dis[to] > dis[i] + w){ dis[to] = dis[i] + w; } } } if(dis[b] >= mod) cout << "-1\n"; else cout << dis[b] << '\n'; } return 0; }

Compilation message (stderr)

toll.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main(){
      | ^~~~
#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...