답안 #51216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51216 2018-06-17T09:01:05 Z robert 관광 (NOI14_sightseeing) C++14
15 / 25
3500 ms 63740 KB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int, int> ii;

vector<vector<ii > > g;

int main(){
	int N, M, Q; cin>>N>>M>>Q;
	g.assign(N+1, vector<ii >());
	int a, b, c;
	for(int m=0; m<M; m++){
		cin>>a>>b>>c;
		g[a].push_back({b, c});
		g[b].push_back({a, c});
	}
	vector<int> d(N+1, -1e9);
	vector<int> v(N+1, 0);
	d[1] = 1e9;
	priority_queue<ii> q;
	q.push({d[1], 1});
	while(!q.empty()){
		ii t = q.top(); q.pop();
		if(v[t.second])
			continue;
		v[t.second] = true;
		for(int x=0; x<g[t.second].size(); x++){
			if(d[g[t.second][x].first]<min(g[t.second][x].second, t.first)){
				d[g[t.second][x].first] = min(g[t.second][x].second, t.first);
				q.push({d[g[t.second][x].first], g[t.second][x].first});
			}
		}
	}
	for(int q=0; q<Q; q++){
		int a;
		cin>>a;
		cout << d[a] << endl;
	}
	return 0;
}

Compilation message

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:30:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int x=0; x<g[t.second].size(); x++){
                ~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 544 KB Output is correct
2 Correct 3 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 3532 KB Output is correct
2 Correct 78 ms 3532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3549 ms 63740 KB Time limit exceeded
2 Halted 0 ms 0 KB -