답안 #489803

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489803 2021-11-24T17:56:36 Z keta_tsimakuridze Cities (BOI16_cities) C++14
22 / 100
2735 ms 46956 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define pii pair<int,int>
#define int long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7, inf = 1e16; // !
int t,n,m,dp[N][35],k;
vector<pii> V[N];
main() {
	cin >> n >> k >> m;
	for(int i = 1; i <= n; i++) for(int j = 1; j < (1 << k); j++) dp[i][j] = inf;
	
	for(int i = 1; i <= k; i++) {
		int b;
		cin >> b;
		dp[b][1 << (i - 1)] = 0;
	}
	for(int i = 1; i <= m; i++) {
		int u,v,w;
		cin >> u >> v >> w;
		V[u].push_back({v,w});
		V[v].push_back({u,w});
	}
	
	for(int j = 1; j < (1 << k); j++) {
		vector<int> sub;
		for(int m = j; ; m = (m - 1) & j) {
			sub.push_back(m);
			if(!m) break;
		}
		for(int i = 1; i <= n; i++) {
			for(int x = 0; x < sub.size(); x++) {
				int a = sub[x];
				for(int m = a; ; m = (m - 1) & a) {
					for(int id = 0; id < V[i].size(); id++) {
						dp[i][a] = min(dp[i][a], dp[i][m] +  dp[V[i][id].f][a ^ m] + V[i][id].s);
					}
					if(!m) break;
				}
			}
		}
	}
	int ans = inf;
	for(int i = 1; i <= n; i++) {
		ans = min(ans, dp[i][(1 << k) - 1]);
	}
	cout << ans;
}

Compilation message

cities.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main() {
      | ^~~~
cities.cpp: In function 'int main()':
cities.cpp:33:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    for(int x = 0; x < sub.size(); x++) {
      |                   ~~^~~~~~~~~~~~
cities.cpp:36:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |      for(int id = 0; id < V[i].size(); id++) {
      |                      ~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 459 ms 46920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5324 KB Output is correct
2 Correct 7 ms 5324 KB Output is correct
3 Incorrect 5 ms 5324 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 861 ms 46956 KB Output is correct
2 Correct 973 ms 46076 KB Output is correct
3 Incorrect 546 ms 39748 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1978 ms 46932 KB Output is correct
2 Correct 2011 ms 46904 KB Output is correct
3 Correct 2735 ms 46036 KB Output is correct
4 Incorrect 1280 ms 39832 KB Output isn't correct
5 Halted 0 ms 0 KB -