제출 #489803

#제출 시각아이디문제언어결과실행 시간메모리
489803keta_tsimakuridzeCities (BOI16_cities)C++14
22 / 100
2735 ms46956 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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++) {
      |                      ~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...