답안 #147835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147835 2019-08-30T21:42:06 Z luciocf Cities (BOI16_cities) C++14
0 / 100
393 ms 21536 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

const int maxn = 2e5+10;
const ll inf = 1e18+10;

int n, cnt=-1;
int a[6];

ll dist[4][maxn];

bool mark[maxn];

vector<pii> grafo[maxn];

void dijkstra(int s)
{
	++cnt;

	memset(mark, 0, sizeof mark);

	for (int i = 1; i <= n; i++)
		dist[cnt][i] = inf;

	priority_queue<pii, vector<pii>, greater<pii>> fila;

	dist[cnt][s] = 0, fila.push({0, s});

	while (!fila.empty())
	{
		int u = fila.top().second; fila.pop();

		if (mark[u]) continue;
		mark[u] = 1;

		for (auto pp: grafo[u])
		{
			int v = pp.first, w = pp.second;

			if (dist[cnt][v] > dist[cnt][u]+1ll*w)
			{
				dist[cnt][v] = dist[cnt][u]+1ll*w;
				fila.push({dist[cnt][v], v});
			}
		}
	}
}

int main(void)
{
	int m, k;
	scanf("%d %d %d", &n, &k, &m);

	for (int i = 1; i <= k; i++)
		scanf("%d", &a[i]);

	for (int i = 1; i <= m; i++)
	{
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);

		grafo[u].push_back({v, w}); grafo[v].push_back({u, w});
	}

	int u = a[1], v = a[2], w = a[3], z = a[4];

	dijkstra(u);
	dijkstra(v);
	dijkstra(w);
	dijkstra(z);

	ll ans = inf;

	for (int i = 1; i <= n; i++)
	{
		if (i == u || i == v || i == w || i == z) continue;

		if (dist[0][i] != inf && dist[1][i] != inf && dist[2][i] != inf && dist[3][i] != inf)
		{  
			ans = min(ans, max(dist[0][i], dist[1][i])+max(dist[2][i], dist[3][i]));
			ans = min(ans, max(dist[0][i], dist[2][i])+max(dist[1][i], dist[3][i]));
			ans = min(ans, max(dist[0][i], dist[3][i])+max(dist[1][i], dist[2][i]));
		}
	}

	printf("%lld\n", ans);
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:56: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:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
cities.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &u, &v, &w);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 5240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 335 ms 20668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 5368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 392 ms 21536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 393 ms 21456 KB Output isn't correct
2 Halted 0 ms 0 KB -