Submission #91987

#TimeUsernameProblemLanguageResultExecution timeMemory
91987emil_physmathEvacuation plan (IZhO18_plan)C++17
23 / 100
547 ms32472 KiB
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
const long long INF=200000000;
const long long MAXN=100005;

vector<pair<long long, long long> > nei[MAXN];
long long dist[MAXN], p[MAXN];

int main()
{
	long long n, m, k, Q;
	cin>>n>>m;
	for (long long i=0; i<m; i++)
	{
		long long u, v, w;
		scanf("%lld%lld%lld", &u, &v, &w);
		nei[u].push_back(make_pair(v, w));
		nei[v].push_back(make_pair(u, w));
	}
	priority_queue< pair<long long,long long> > q;
	for (long long u=1; u<=n; u++) dist[u]=INF;
	cin>>k;
	for (long long i=0; i<k; i++)
	{
		long long s;
		scanf("%lld", &s);
		dist[s]=0;
		q.push(make_pair(0, s));
	}
	while (!q.empty()) {
		long long v=q.top().second, cur_d=-q.top().first;
		q.pop();
		if (cur_d>dist[v])  continue;
		for (long long j=0; j<nei[v].size(); j++) {
			long long to=nei[v][j].first,
				len=nei[v][j].second;
			if (dist[v]+len<dist[to]) {
				dist[to]=dist[v]+len;
				p[to]=v;
				q.push(make_pair(-dist[to], to));
			}
		}
	}
	cin>>Q;
	while (Q--)
	{
		long long s, e;
		scanf("%lld%lld", &s, &e);
		printf("%lld\n", min(dist[s], dist[e]));
	}

	char I;
	cin >> I;
	return 0;
}

Compilation message (stderr)

plan.cpp: In function 'int main()':
plan.cpp:37:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (long long j=0; j<nei[v].size(); j++) {
                       ~^~~~~~~~~~~~~~
plan.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &u, &v, &w);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &s);
   ~~~~~^~~~~~~~~~~~
plan.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &s, &e);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...