답안 #765305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765305 2023-06-24T10:35:47 Z raysh07 악어의 지하 도시 (IOI11_crocodile) C++17
89 / 100
435 ms 77128 KB
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define INF (int)(1e18 + 1)
#define int long long

int n, m;
const int maxn = 1e5 + 69;
vector <pair<int, int>> adj[maxn];
int dp[maxn][2];

int32_t travel_plan(int32_t N, int32_t M, int32_t R[][2], int32_t L[], int32_t K, int32_t P[])
{
	n = N, m = M;
	for (int i = 0; i < n; i++){
		dp[i][0] = dp[i][1] = INF;
	}

	for (int i = 0; i < m; i++){
		adj[R[i][0]].push_back({R[i][1], L[i]});
		adj[R[i][1]].push_back({R[i][0], L[i]});
	}

	for (int i = 0; i < K; i++){
		dp[P[i]][0] = dp[P[i]][1] = 0;
	}

	//dp[i][0] = best path, dp[i][1] = second best path, update only with help of second best path values 
	priority_queue <pair<int, int>> pq;
	for (int i = 0; i < n; i++){
		pq.push({-dp[i][1], i});
	}

	while (!pq.empty()){
		auto pi = pq.top();
		pq.pop();

		int d = -pi.first;
		int u = pi.second;

		if (d != dp[u][1]) continue;

		for (pair <int, int> pi : adj[u]){
			int v = pi.first;
			int w = pi.second;
			int val = d + w;

			if (val < dp[v][0]){
				dp[v][1] = dp[v][0];
				dp[v][0] = val;
				pq.push({-dp[v][1], v});
			} else if (val < dp[v][1]) {
				dp[v][1] = val;
				pq.push({-dp[v][1], v});
			}
		}
	}

	return (int32_t)dp[0][1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2772 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 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2772 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 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 3 ms 3028 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 3 ms 3284 KB Output is correct
13 Correct 3 ms 3320 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 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2772 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 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 3 ms 3028 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 3 ms 3284 KB Output is correct
13 Correct 3 ms 3320 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
16 Correct 371 ms 68832 KB Output is correct
17 Correct 95 ms 18628 KB Output is correct
18 Correct 106 ms 20860 KB Output is correct
19 Correct 435 ms 77128 KB Output is correct
20 Correct 254 ms 55124 KB Output is correct
21 Correct 38 ms 9420 KB Output is correct
22 Incorrect 259 ms 51020 KB Output isn't correct
23 Halted 0 ms 0 KB -