Submission #864519

#TimeUsernameProblemLanguageResultExecution timeMemory
864519maks007Toll (BOI17_toll)C++14
56 / 100
3006 ms12340 KiB
// Bismi ALlah
#include "bits/stdc++.h"

using namespace std;

signed main () {
	int n, m, k, query;
	cin >> k >> n >> m >> query;
	vector<pair <int,int>> g[n], revG[n];
	for(int i = 0; i < m; i ++) {
		int u, v;
		cin >> u >> v;
		int w;
		cin >> w;
		revG[v].push_back({u, w});
		g[u].push_back({v, w});
	}
	priority_queue <pair <int,int>> q;
	vector <int> dist(n, 1e9);
	dist[0] = 0;
	q.push({0, 0});
	while(!q.empty()) {
		int v = q.top().second, cur_d = q.top().first;
		q.pop();
		if(cur_d > dist[v]) continue;
		for(auto [u, w] : g[v]) {
			if(dist[u] > dist[v] + w) {
				dist[u] = dist[v] + w;
				q.push({-dist[u], u});
			}
		}
	}
	while(query --) {
		int a, b;
		cin >> a >> b;
		
			int dp[n];
			for(int i = 0; i < n; i ++) dp[i] = 1e9;
			dp[b] = 0;
			for(int i = n - 1; i >= 0; i--) {
				if(dp[i] != 1e9) {
					for(auto [u, w] : revG[i]) {
						dp[u] = min(dp[u], dp[i] + w);
					}
				}
			}
			if(dp[a] == 1e9) cout << -1 << "\n";
			else cout << dp[a] << "\n";
		
	}
	return 0;
}

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:26:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   26 |   for(auto [u, w] : g[v]) {
      |            ^
toll.cpp:42:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |      for(auto [u, w] : revG[i]) {
      |               ^
#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...