답안 #526688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526688 2022-02-16T01:40:59 Z siewjh Autobus (COCI22_autobus) C++17
30 / 70
1000 ms 7468 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1'000'000'007;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int nodes, edges; cin >> nodes >> edges;
	vector<pair<pair<int, int>, int>> edgelist(edges);
	for (int i = 0; i < edges; i++) {
		int a, b, t; cin >> a >> b >> t;
		edgelist[i] = { {a, b},t };
	}
	int maxbus, queries; cin >> maxbus >> queries;
	maxbus = min(maxbus, nodes - 1);
	int dist[71][71][71];
	for (int i = 0; i < 71; i++)
		for (int j = 0; j < 71; j++)
			for (int k = 0; k < 71; k++)
				dist[i][j][k] = inf;
	for (int i = 1; i <= nodes; i++) {
		dist[i][i][0] = 0;
		for (int j = 1; j <= maxbus; j++)
			for (auto e : edgelist) {
				int a = e.first.first, b = e.first.second, t = e.second;
				dist[i][b][j] = min(dist[i][b][j], dist[i][a][j - 1] + t);
			}
	}
	for (int i = 0; i < queries; i++) {
		int a, b; cin >> a >> b;
		int ans = inf;
		for (int j = 0; j <= maxbus; j++) ans = min(ans, dist[a][b][j]);
		cout << ((ans == inf) ? -1 : ans) << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 4 ms 1712 KB Output is correct
3 Correct 3 ms 1740 KB Output is correct
4 Correct 4 ms 1612 KB Output is correct
5 Correct 4 ms 1740 KB Output is correct
6 Correct 9 ms 1740 KB Output is correct
7 Correct 10 ms 1740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 7 ms 1740 KB Output is correct
8 Correct 14 ms 1740 KB Output is correct
9 Correct 4 ms 1612 KB Output is correct
10 Correct 19 ms 1724 KB Output is correct
11 Correct 23 ms 1776 KB Output is correct
12 Correct 91 ms 1756 KB Output is correct
13 Correct 834 ms 7468 KB Output is correct
14 Execution timed out 1063 ms 7376 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 2 ms 1612 KB Output is correct
8 Correct 4 ms 1712 KB Output is correct
9 Correct 3 ms 1740 KB Output is correct
10 Correct 4 ms 1612 KB Output is correct
11 Correct 4 ms 1740 KB Output is correct
12 Correct 9 ms 1740 KB Output is correct
13 Correct 10 ms 1740 KB Output is correct
14 Correct 7 ms 1740 KB Output is correct
15 Correct 14 ms 1740 KB Output is correct
16 Correct 4 ms 1612 KB Output is correct
17 Correct 19 ms 1724 KB Output is correct
18 Correct 23 ms 1776 KB Output is correct
19 Correct 91 ms 1756 KB Output is correct
20 Correct 834 ms 7468 KB Output is correct
21 Execution timed out 1063 ms 7376 KB Time limit exceeded
22 Halted 0 ms 0 KB -