제출 #1128077

#제출 시각아이디문제언어결과실행 시간메모리
1128077stdfloatToll (BOI17_toll)C++20
0 / 100
26 ms3360 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int k, n, m, q;
	cin >> k >> n >> m >> q;

	vector<pair<int, int>> E[n];
	while (m--) {
		int x, y, w;
		cin >> x >> y >> w;

		E[y].push_back({x, w});
	}

	while (q--) {
		int x, y;
		cin >> x >> y;

		vector<int> dp(n, (int)2e9);
		dp[x] = 0;
		for (int i = x + 1; i <= n; i++) {
			for (auto [j, w] : E[i])
				dp[i] = min(dp[i], dp[j] + w);
		}

		cout << (dp[y] == (int)2e9 ? -1 : dp[y]) << '\n';
	}
}
#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...