답안 #864522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864522 2023-10-23T07:13:18 Z maks007 Toll (BOI17_toll) C++14
0 / 100
74 ms 3584 KB
// 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];
	for(int i = 0; i < m; i ++) {
		int u, v;
		cin >> u >> v;
		int w;
		cin >> w;
		g[u].push_back({v, w});
	}
	int dp[n], parent[n];
	for(int i = 0; i < n; i ++) dp[i] = 1e9, parent[i] = 0;
	for(int i = 0; i < k; i ++) dp[i] = 0;
	for(int i = 0; i < n; i ++) {
		if(dp[i] == 1e9) continue;
		for(auto [u, w] : g[i]) {
			if(dp[u] > dp[i] + w) {
				dp[u] = dp[i] + w;
				parent[u] = dp[i];
			}
		}
	}
	while(query --) {
		int a, b;
		cin >> a >> b;
		if(dp[b] == 1e9) cout << -1 << "\n";
		else
		cout << dp[b] - dp[a] << "\n";
	}
	return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:22:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   22 |   for(auto [u, w] : g[i]) {
      |            ^
toll.cpp:17:13: warning: variable 'parent' set but not used [-Wunused-but-set-variable]
   17 |  int dp[n], parent[n];
      |             ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 3584 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 3480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 3584 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -