답안 #526703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526703 2022-02-16T02:22:32 Z hmm789 Autobus (COCI22_autobus) C++14
30 / 70
1000 ms 49792 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, e, x, y, w, k, q;
	cin >> n >> e;
	int adj[n][n];
	pair<int, int> dist[n][n];
	memset(adj, -1, sizeof(adj));
	memset(dist, -1, sizeof(dist));
	for(int i = 0; i < e; i++) {
		cin >> x >> y >> w;
		x--; y--;
		if(adj[x][y] == -1) adj[x][y] = w;
		else adj[x][y] = min(adj[x][y], w);
	}
	cin >> k >> q;
	priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;
	for(int i = 0; i < n; i++) {
		dist[i][i] = make_pair(0, 0);
		pq.push(make_pair(0, make_pair(i, 0)));
		while(!pq.empty()) {
			pair<int, pair<int, int>> c = pq.top();
			pq.pop();
			if(c.second.second == k) continue;
			for(int j = 0; j < n; j++) {
				if(adj[c.second.first][j] == -1) continue;
				if(dist[i][j].first == -1 || dist[i][j].first > c.first + adj[c.second.first][j]) {
					dist[i][j].first = c.first + adj[c.second.first][j];
					dist[i][j].second = c.second.second+1;
					pq.push(make_pair(dist[i][j].first, make_pair(j, c.second.second+1)));
				} else if(c.second.second+1 < dist[i][j].second) pq.push(make_pair(c.first + adj[c.second.first][j], make_pair(j, c.second.second+1)));
			}
		}
	}
	for(int i = 0; i < q; i++) {
		cin >> x >> y;
		x--; y--;
		cout << dist[x][y].first << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 5 ms 332 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 34 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 37 ms 748 KB Output is correct
8 Correct 34 ms 744 KB Output is correct
9 Correct 15 ms 460 KB Output is correct
10 Correct 46 ms 460 KB Output is correct
11 Execution timed out 1093 ms 49792 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 5 ms 332 KB Output is correct
12 Correct 4 ms 332 KB Output is correct
13 Correct 34 ms 468 KB Output is correct
14 Correct 37 ms 748 KB Output is correct
15 Correct 34 ms 744 KB Output is correct
16 Correct 15 ms 460 KB Output is correct
17 Correct 46 ms 460 KB Output is correct
18 Execution timed out 1093 ms 49792 KB Time limit exceeded
19 Halted 0 ms 0 KB -