제출 #1369346

#제출 시각아이디문제언어결과실행 시간메모리
1369346blackscreen1Cities (BOI16_cities)C++20
100 / 100
1162 ms39928 KiB
#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll n, m, t, t1, t2, t3;
ll im[6];
vector<pll> adj[100005];
ll dp[32][100005];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> t >> m;
	iloop(0, t) {cin >> im[i]; im[i]--;}
	iloop(0, m) {
		cin >> t1 >> t2 >> t3;
		t1--, t2--;
		adj[t1].push_back({t3, t2});
		adj[t2].push_back({t3, t1});
	}
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	iloop(1, 1<<t) {
		jloop(0, n) dp[i][j] = INF;
		if (__builtin_popcount(i) == 1) dp[i][im[31 - __builtin_clz(i)]] = 0;
		else {
			for (int k = i-1; k; k = (k-1)&i) {
				jloop(0, n) dp[i][j] = min(dp[i][j], dp[k][j] + dp[i^k][j]);
			}
		}
		jloop(0, n) pq.push({dp[i][j], j});
		while (pq.size()) {
			pll nd = pq.top();
			pq.pop();
			if (dp[i][nd.second] < nd.first) continue;
			for (auto it : adj[nd.second]) {
				if (nd.first + it.first < dp[i][it.second]) {
					dp[i][it.second] = nd.first + it.first;
					pq.push({dp[i][it.second], it.second});
				}
			}
		}
	}
	cout << *min_element(dp[(1<<t)-1], dp[(1<<t)-1] + n);
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…