답안 #124518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124518 2019-07-03T13:15:37 Z streifi 관광 (NOI14_sightseeing) C++14
15 / 25
3500 ms 128492 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 0x3f3f3f3f;

struct edge {
	int v, w;
	bool operator<(const edge &other) const {
		return w < other.w;
	}
};

int V, E, Q;
vector< vector<edge> > adj;
vector<int> dist;

void dijkstra(int start) {
	priority_queue<edge> pq;
	dist.assign(V, 0);
	dist[start] = INF;
	pq.push({start, INF});
	
	while (pq.size()) {
		edge cur = pq.top();
		pq.pop();
		if (cur.w < dist[cur.v])
			continue;
		
		for (edge e: adj[cur.v]) {
			int newdist = min(cur.w, e.w);
			if (newdist > dist[e.v]) {
				dist[e.v] = newdist;
				pq.push({e.v, newdist});
			}
		}
	}
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> V >> E >> Q;
	adj.resize(V);
	for (int e = 0; e < E; ++e) {
		int u, v, q;
		cin >> u >> v >> q;
		adj[u-1].push_back({v-1, q});
		adj[v-1].push_back({u-1, q});
	}
	dijkstra(0);
	for (int q = 0; q < Q; ++q) {
		int X;
		cin >> X;
		cout << dist[X-1] << endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 3704 KB Output is correct
2 Correct 49 ms 3320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3510 ms 128492 KB Time limit exceeded
2 Halted 0 ms 0 KB -