Submission #51222

# Submission time Handle Problem Language Result Execution time Memory
51222 2018-06-17T09:03:29 Z robert Sightseeing (NOI14_sightseeing) C++14
15 / 25
3500 ms 104388 KB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int, int> ii;

vector<vector<ii > > g;

int main(){
	iostream::sync_with_stdio(false);
	cin.tie(0);
	int N, M, Q; scanf("%d %d %d", &N, &M, &Q);
	g.assign(N+1, vector<ii >());
	int a, b, c;
	for(int m=0; m<M; m++){
		scanf("%d %d %d", &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;
		scanf("%d", &a);
		printf("%d\n", d[a]);
	}
	return 0;
}

Compilation message

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:32:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int x=0; x<g[t.second].size(); x++){
                ~^~~~~~~~~~~~~~~~~~~
sightseeing.cpp:14:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N, M, Q; scanf("%d %d %d", &N, &M, &Q);
               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a);
   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 556 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 3552 KB Output is correct
2 Correct 41 ms 3552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3555 ms 104388 KB Time limit exceeded
2 Halted 0 ms 0 KB -