답안 #761003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761003 2023-06-19T02:09:50 Z SanguineChameleon 악어의 지하 도시 (IOI11_crocodile) C++17
100 / 100
368 ms 61544 KB
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;

const int maxN = 1e5 + 20;
const int inf = 1e9 + 20;
int dist[maxN];
int best1[maxN];
int best2[maxN];
vector<pair<int, int>> adj[maxN];

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
	for (int i = 0; i < M; i++) {
		int u = R[i][0];
		int v = R[i][1];
		int w = L[i];
		adj[u].emplace_back(v, w);
		adj[v].emplace_back(u, w);
	}
	for (int i = 0; i < N; i++) {
		best1[i] = inf;
		best2[i] = inf;
		dist[i] = inf;
	}
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q;
	for (int i = 0; i < K; i++) {
		dist[P[i]] = 0;
		Q.emplace(0, P[i]);
	}
	while (!Q.empty()) {
		int cur = Q.top().first;
		int u = Q.top().second;
		Q.pop();
		if (dist[u] != cur) {
			continue;
		}
		for (auto e: adj[u]) {
			int v = e.first;
			int w = e.second;
			if (dist[u] + w < best1[v]) {
				best2[v] = best1[v];
				best1[v] = dist[u] + w;
			}
			else if (dist[u] + w < best2[v]) {
				best2[v] = dist[u] + w;
			}
			if (best2[v] < dist[v]) {
				dist[v] = best2[v];
				Q.emplace(dist[v], v);
			}
		}
	}
	return dist[0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2660 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2664 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2676 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2660 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2664 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2676 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 1 ms 2664 KB Output is correct
11 Correct 2 ms 2800 KB Output is correct
12 Correct 4 ms 3156 KB Output is correct
13 Correct 3 ms 3180 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2660 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2664 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2676 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 1 ms 2664 KB Output is correct
11 Correct 2 ms 2800 KB Output is correct
12 Correct 4 ms 3156 KB Output is correct
13 Correct 3 ms 3180 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
16 Correct 299 ms 57588 KB Output is correct
17 Correct 53 ms 14028 KB Output is correct
18 Correct 67 ms 15568 KB Output is correct
19 Correct 368 ms 61544 KB Output is correct
20 Correct 216 ms 49532 KB Output is correct
21 Correct 27 ms 7768 KB Output is correct
22 Correct 231 ms 46136 KB Output is correct