답안 #864527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864527 2023-10-23T07:19:45 Z maks007 Toll (BOI17_toll) C++14
10 / 100
118 ms 6844 KB
// Bismi ALlah
#include "bits/stdc++.h"

using namespace std;

#define int long long

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][k];
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < k; j ++) dp[i][j] = LLONG_MAX;
	}
	for(int j = 0; j < k; j ++) {
		dp[j][j] = 0;
		for(int i = 0; i < n; i ++) {
			if(dp[i][j] != LLONG_MAX) {
				for(auto [u, w] : g[i]) {
					dp[u][j] = min(dp[u][j], dp[i][j] + w);
				}
			}
		}
	}
	while(query --) {
		int a, b;
		cin >> a >> b;
		int mn = LLONG_MAX;
		for(int i = 0; i < k; i ++) {
			if(dp[b][i] == LLONG_MAX || dp[a][i] == LLONG_MAX) continue;
			mn = min(mn, dp[b][i] - dp[a][i]);
		}
		if(mn == LLONG_MAX) cout << -1 << "\n";
		else cout << mn << "\n";
	}
	return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:27:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |     for(auto [u, w] : g[i]) {
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 3576 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 4944 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 15 ms 348 KB Output is correct
8 Correct 15 ms 348 KB Output is correct
9 Correct 45 ms 3348 KB Output is correct
10 Correct 118 ms 6736 KB Output is correct
11 Correct 85 ms 5196 KB Output is correct
12 Correct 61 ms 4692 KB Output is correct
13 Correct 97 ms 6844 KB Output is correct
14 Correct 59 ms 4436 KB Output is correct
15 Correct 51 ms 4184 KB Output is correct
16 Correct 51 ms 4236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 3576 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -