Submission #62050

# Submission time Handle Problem Language Result Execution time Memory
62050 2018-07-27T10:07:28 Z Crown Cities (BOI16_cities) C++14
0 / 100
262 ms 44956 KB
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector< ii > vii;

const int maxn = 1e5+5;
const int maxk = 5;

vii adj[maxn];
int n, k, m;
int imp[maxk+5];
ll dist[(1<<5)+5][maxn];
int mark[maxn];

struct node
{
	int bit, u;
	ll d;
	node(int _bit, int _u, ll _d)
	{
		bit = _bit; u = _u; d = _d;
	}
	bool operator < (node other) const
	{
		return d> other.d;
	}
};

int main()
{
	memset(mark, -1, sizeof mark);
	scanf("%d %d %d", &n, &k, &m);
	for(int i = 0; i< k; i++)
	{
		scanf("%d", imp+i);
		mark[imp[i]] = i;
	}
	for(int i = 1; i<= m; i++)
	{
		int u, v, w; scanf("%d %d %d", &u, &v, &w);
		adj[u].pb(ii(v, w));
		adj[v].pb(ii(u, w));
	}
	memset(dist, 32, sizeof dist);
	priority_queue<node> pq;
	for(int i = 1; i<= n; i++)
	{
		dist[0][i] = 0;
		pq.push(node(0, i, 0));
	}
	for(int i = 0; i< k; i++)
	{
		dist[1<<i][imp[i]] = 0;
		pq.push(node(1<<i, imp[i], 0));
	}
	while(!pq.empty())
	{
		node x = pq.top(); pq.pop();
		int bit = x.bit, u = x.u;
		ll d = x.d;
		if(d> dist[bit][u]) continue;
		for(auto edge : adj[u])
		{
			int v = edge.X, w = edge.Y;
			if(d+w < dist[bit][v])
			{
				dist[bit][v] = d+w;
				for(int comp = 0; comp< (1<<k); comp++)
				{
					if(dist[bit|comp][v]> dist[bit][v]+dist[comp][v])
					{
						dist[bit|comp][v] = dist[bit][v]+dist[comp][v];
						pq.push(node(bit|comp, v, dist[bit|comp][v]));
					}
				}
			}
		}
	}
	ll best = 1e18;
	for(int i = 1; i<= n; i++) best = min(best, dist[(1<<k)-1][i]);
	printf("%lld\n", best);
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &k, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", imp+i);
   ~~~~~^~~~~~~~~~~~~
cities.cpp:45:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int u, v, w; scanf("%d %d %d", &u, &v, &w);
                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 31992 KB Output is correct
2 Correct 31 ms 32232 KB Output is correct
3 Incorrect 39 ms 32232 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 254 ms 44880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 44880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 250 ms 44956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 262 ms 44956 KB Output isn't correct
2 Halted 0 ms 0 KB -