Submission #52046

# Submission time Handle Problem Language Result Execution time Memory
52046 2018-06-23T11:02:09 Z mrtsima22 Evacuation plan (IZhO18_plan) C++17
0 / 100
339 ms 13048 KB
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
int n,m,q,Q,hoi;
int a,b,c,k,N[100003];
int min_Dd[100004];
vector<pair<int,int> >v[100003];
void go(int a)
{
	vector<int>min_distance(n,10000);
	min_distance[a]=0;
	set<pair<int,int> >active;
	active.insert({0,a});
	while(active.size())
	{
		int where=(*active.begin()).second;
		active.erase(active.begin());
		for(int i=0;i<v[where].size();i++)
		{
			if(min_distance[v[where][i].first]>min_distance[where]+v[where][i].second)
			{
				active.erase({min_distance[v[where][i].first],v[where][i].second});
				min_distance[v[where][i].first]=min_distance[where]+v[where][i].second;
				active.insert({min_distance[v[where][i].first],v[where][i].first});
			}
		}
	}
	for(int i=0;i<=n;i++)
	min_Dd[i]=min_distance[i];
}
int main(){std::ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=0;i<m;i++)
{
	cin>>a>>b>>c;
	v[a].push_back({b,c});
	v[b].push_back({a,c});
}
cin>>k;
for(int i=0;i<k;i++)
{
	cin>>N[i];
}
cin>>Q;
for(int i=0;i<Q;i++)
{
	cin>>a>>b;
	go(a);
	hoi=-lmax;
	for(int j=0;j<k;j++)
	{
		hoi=max(hoi,min_Dd[N[j]]);
	}
	go(b);
	for(int j=0;j<k;j++)
	{
		hoi=max(hoi,min_Dd[N[j]]);
	}
	cout<<hoi<<endl;
}
}
/*
 
                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *
11 17
10 9 1
10 11 2
10 7 1
9 11 1
9 8 1
8 2 1
8 1 1
2 1 1
2 3 1
3 1 1
3 4 1
4 5 1
5 1 1
1 7 1
7 5 1
7 11 1
4 6 1
2
2 4
1
7 10
 
 
*/

Compilation message

plan.cpp: In function 'void go(int)':
plan.cpp:20:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<v[where].size();i++)
               ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 5368 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 5368 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 339 ms 13048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 5368 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -