Submission #714740

#TimeUsernameProblemLanguageResultExecution timeMemory
714740ajab_01Toll (BOI17_toll)C++17
17 / 100
51 ms6208 KiB
#include<bits/stdc++.h> using namespace std; const int INF = 1e9 + 9; const int N = 1e5 + 5; const int O = 3e3 + 3; vector<pair<int , int> > g[N] , query; priority_queue<pair<int , int> > pq; int val[N] , pre[N] , pr[N] , k , n , m , o; bool vis[N] , ch = 1; void dijkstra(){ val[0] = 0; pq.push({0 , 0}); while(!pq.empty()){ int v = pq.top().second; pq.pop(); if(vis[v]) continue; vis[v] = 1; for(auto i : g[v]){ int u = i.first , w = i.second; if(val[u] > val[v] + w){ val[u] = val[v] + w; pq.push({-val[u] , u}); } } } } int main(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); memset(pr , -1 , sizeof(pr)); fill(val , val + N , INF); cin >> k >> n >> m >> o; for(int i = 0 ; i < m ; i++){ int u , v , w; cin >> u >> v >> w; g[u].push_back({v , w}); } for(int i = 0 ; i < o ; i++){ int a , b; cin >> a >> b; query.push_back({a , b}); if(a) ch = 0; } if(k == 1){ int bef = 0; for(int i = 0 ; i < n ; i++){ if(i == bef) pre[i] = 0; else pre[i] = pre[i - 1] + g[i - 1][0].second; pr[i] = bef; if(!g[i].size()){ while(!g[i].size())i++; bef = i; i--; } } for(auto i : query){ if(pr[i.first] == -1 || pr[i.second] == -1 || pr[i.first] != pr[i.second] || i.second < i.first) cout << -1 << '\n'; else cout << pre[i.second] - pre[i.first] << '\n'; } return 0; } if(ch){ dijkstra(); for(auto i : query){ if(val[i.second] == INF) cout << -1 << '\n'; else cout << val[i.second] << '\n'; } return 0; } cout << "jalebe" << '\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...