Submission #466463

# Submission time Handle Problem Language Result Execution time Memory
466463 2021-08-19T11:00:58 Z shanem_1401 Cities (BOI16_cities) C++14
14 / 100
308 ms 19936 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
int n, m, k;
int main()
{
	scanf("%d %d %d",& n,& k,& m);
	vector<int>penting;
	for(int i=0; i<k; i++)
	{
		int temp;
		scanf("%d",& temp);
		penting.push_back(temp);
	}
	penting.resize(3, penting[0]);
	vector<pii>v[n+2];
	k=3;
	for(int i=0; i<m; i++)
	{
		int from, to, cost;
		scanf("%d %d %d",& from,& to,& cost);
		v[from].pb(mp(cost, to));
		v[to].pb(mp(cost, from));
	}
	ll dist[k+2][n+2];
	for(int i=0; i<k; i++)
		fill(dist[i]+1, dist[i]+n+1, 2e18);
	for(int i=0; i<k; i++)
	{
	//	printf("---i: %d\n", i);
		priority_queue<pair<ll, int> >pq;
		pq.push(mp(0, penting[i]));
		dist[i][penting[i]]=0;
		while(!pq.empty())
		{
			ll cost=-pq.top().fi;
			int from=pq.top().se;
			pq.pop();
			if(dist[i][from]!=cost)
				continue;
	//		printf("from: %d, cost: %lld\n", from, cost);
			for(int j=0; j<v[from].size(); j++)
			{
				int to=v[from][j].se;
				ll price=v[from][j].fi+cost;
				if(dist[i][to]>price)
				{
					dist[i][to]=price;
					pq.push(mp(-price, to));
				}
			}
		}
	}
	ll mini=2e18;
	for(int i=1; i<=n; i++)
	{
		ll total=0;
		for(int j=0; j<k; j++)
			total+=dist[j][i];
		mini=min(mini, total);
	}
	printf("%lld\n", mini);
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |    for(int j=0; j<v[from].size(); j++)
      |                 ~^~~~~~~~~~~~~~~
cities.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d %d %d",& n,& k,& m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d",& temp);
      |   ~~~~~^~~~~~~~~~~~~
cities.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   scanf("%d %d %d",& from,& to,& cost);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 308 ms 18908 KB Output is correct
2 Correct 297 ms 19936 KB Output is correct
3 Correct 142 ms 11680 KB Output is correct
4 Correct 79 ms 8488 KB Output is correct
5 Correct 252 ms 18812 KB Output is correct
6 Correct 75 ms 8448 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 269 ms 18912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 264 ms 18892 KB Output isn't correct
2 Halted 0 ms 0 KB -