답안 #124552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124552 2019-07-03T13:44:16 Z NMAC427 관광 (NOI14_sightseeing) C++17
15 / 25
3331 ms 262148 KB
// https://oj.uz/problem/view/NOI14_sightseeing

#include <bits/stdc++.h>

#define int int64_t
#define coutV(x) for (const auto& e: x) {cerr << e << " ";} cerr << "\n"

using namespace std;

int V, E, Q;

vector<vector<pair<int, int>>> adj;
vector<int> xI;

signed main() {
	
	#ifndef __APPLE__
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	#endif

	cin >> V >> E >> Q;

	adj.resize(V);
	xI.resize(Q);


	for (int i = 0; i < E; i++) {
		int v1, v2, q;
		cin >> v1 >> v2 >> q;

		adj[v1 - 1].emplace_back(v2 - 1, q);
		adj[v2 - 1].emplace_back(v1 - 1, q);
	}

	for (int i = 0; i < Q; i++) {
		cin >> xI[i];
	}


	// Dijkstra

	vector<int> visited (V, -1);
	priority_queue<pair<int, int>> pq;
	pq.push({INT64_MAX, 0});

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

		int v = top.second;
		int pathQ = top.first;

		if (visited[v] != -1) {
			continue;
		}

		visited[v] = pathQ;

		for (const auto& child: adj[v]) {
			pq.push({min(child.second, pathQ), child.first});
		}
	}

	for (const auto x: xI) {
		cout << visited[x - 1] << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 756 KB Output is correct
2 Correct 1 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 4852 KB Output is correct
2 Correct 51 ms 4040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3331 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -