답안 #106257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
106257 2019-04-17T16:36:26 Z tincamatei 악어의 지하 도시 (IOI11_crocodile) C++14
0 / 100
6 ms 2816 KB
#include "crocodile.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 100000;
const int INF = 1000000001;

vector<pair<int, int> > graph[MAX_N];
int dp[MAX_N];
int best[MAX_N][2];

void dijkstra(int N, int K, int P[]) {
	priority_queue<pair<int, int> > pq;

	for(int i = 0; i < K; ++i) {
		dp[P[i]] = 0;
		best[P[i]][0] = best[P[i]][1] = 0;
		pq.push(make_pair(0, P[i]));
	}

	while(!pq.empty()) {
		int nod = pq.top().second;
		int cost = -pq.top().first;

		pq.pop();

		if(best[nod][1] == cost) {
			dp[nod] = cost;

			for(auto it: graph[nod]) {
				int cost2 = cost + it.second;
				if(cost2 < best[it.first][0]) {
					best[it.first][1] = best[it.first][0];
					best[it.first][0] = cost2;

					pq.push({-best[it.first][0], it.first});
				} else if(cost2 < best[it.first][1]) {
					best[it.first][1] = cost2;

					pq.push({-cost2, it.first});
				}
			}
		}
	}
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
  for(int i = 0; i < M; ++i) {
		graph[R[i][0]].push_back(make_pair(R[i][1], L[i]));
		graph[R[i][1]].push_back(make_pair(R[i][0], L[i]));
	}
	for(int i = 0; i < N; ++i)
		best[i][0] = best[i][1] = INF;
	
	dijkstra(N, K, P);

	return dp[0];
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Incorrect 6 ms 2816 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Incorrect 6 ms 2816 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Incorrect 6 ms 2816 KB Output isn't correct
5 Halted 0 ms 0 KB -