제출 #1128064

#제출 시각아이디문제언어결과실행 시간메모리
1128064stdfloatToll (BOI17_toll)C++20
100 / 100
2008 ms4616 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;

		if (x > y) {
			cout << "-1\n";
			continue;
		}

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

		cout << (dp[y] == (int)1e9 ? -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...