답안 #96233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96233 2019-02-07T11:17:40 Z ics0503 Cities (BOI16_cities) C++14
37 / 100
6000 ms 35760 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
struct xy {int x, y;};
vector<xy>edge[121212];
priority_queue<pair<long long,int>>H;
long long D[1 << 5][121212], L[6];
int  main() {
	long long n, m, k; scanf("%lld%lld%lld", &n, &k, &m);
	long long i, j;
	for (i = 0; i < k; i++)scanf("%lld", &L[i]);
	for (i = 0; i < m; i++) {
		long long s, e, w; scanf("%lld%lld%lld", &s, &e, &w);
		edge[s].push_back({ e,w });
		edge[e].push_back({ s,w });
	}
	long long inf = 1e18;
	for (i = 0; i < (1 << k); i++)for (j = 1; j <= n; j++)D[i][j] = inf;
	for (i = 0; i < k; i++)D[(1 << i)][L[i]] = 0;
	for (i = 1; i < (1 << k); i++) {
		for (j = 1; j <= n; j++) for (int p = 0; p < i; p++) if ((i | p) == i)D[i][j] = min(D[i][j], D[p][j]+D[i^p][j]);
		for (j = 1; j <= n; j++) if (D[i][j]<inf)H.push({ D[i][j],j });
		while (!H.empty()) {
			pair<long long, int> now = H.top(); H.pop();
			if (now.first != D[i][now.second])continue;
			for (j = 0; j < edge[now.second].size(); j++) {
				long long nxt = edge[now.second][j].x, w = edge[now.second][j].y;
				if (D[i][nxt] > D[i][now.second] + w) {
					D[i][nxt] = D[i][now.second] + w;
					H.push({ D[i][nxt], nxt });
				}
			}
		}
	}
	long long ans = inf;
	for (i = 1; i <= n; i++)ans = min(ans, D[(1 << k) - 1][i]);
	printf("%lld", ans);
	return 0;
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:16:28: warning: narrowing conversion of 'e' from 'long long int' to 'int' inside { } [-Wnarrowing]
   edge[s].push_back({ e,w });
                            ^
cities.cpp:16:28: warning: narrowing conversion of 'w' from 'long long int' to 'int' inside { } [-Wnarrowing]
cities.cpp:17:28: warning: narrowing conversion of 's' from 'long long int' to 'int' inside { } [-Wnarrowing]
   edge[e].push_back({ s,w });
                            ^
cities.cpp:17:28: warning: narrowing conversion of 'w' from 'long long int' to 'int' inside { } [-Wnarrowing]
cities.cpp:28:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (j = 0; j < edge[now.second].size(); j++) {
                ~~^~~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:11:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  long long n, m, k; scanf("%lld%lld%lld", &n, &k, &m);
                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:13:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 0; i < k; i++)scanf("%lld", &L[i]);
                         ~~~~~^~~~~~~~~~~~~~~
cities.cpp:15:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   long long s, e, w; scanf("%lld%lld%lld", &s, &e, &w);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 3192 KB Output is correct
2 Correct 4 ms 3192 KB Output is correct
3 Correct 4 ms 3192 KB Output is correct
4 Correct 4 ms 3320 KB Output is correct
5 Correct 4 ms 3320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6071 ms 16828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 3452 KB Output is correct
2 Correct 22 ms 3448 KB Output is correct
3 Correct 45 ms 3476 KB Output is correct
4 Correct 39 ms 3320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6052 ms 23228 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6092 ms 35760 KB Time limit exceeded
2 Halted 0 ms 0 KB -