답안 #648454

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648454 2022-10-06T15:06:19 Z ymm Cities (BOI16_cities) C++17
14 / 100
5467 ms 47436 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 100'010;
const ll inf = 1e17;
const int K = 5;
ll dis[1<<K][N];
vector<pll> A[N];
int imp[K];
int n, k, m;

void dij(int msk)
{
	set<pll> s;
	int fi = __builtin_ctz(msk);
	Loop (v,0,n) {
		dis[msk][v] = dis[msk ^ (1<<fi)][v] + dis[1<<fi][v];
		s.insert({dis[msk][v], v});
	}
	while (s.size()) {
		auto [d, v] = *s.begin();
		s.erase(s.begin());
		for (auto [u, w] : A[v]) {
			if (d + w < dis[msk][u]) {
				s.erase( {dis[msk][u], u});
				dis[msk][u] = d + w;
				s.insert({dis[msk][u], u});
			}
		}
	}
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n >> k >> m;
	Loop (i,0,k) {
		cin >> imp[i];
		--imp[i];
	}
	Loop (i,0,m) {
		ll v, u, w;
		cin >> v >> u >> w;
		--v; --u;
		A[v].push_back({u, w});
		A[u].push_back({v, w});
	}
	Loop (msk,1,1<<k) Loop (v,0,n)
		dis[msk][v] = inf;
	Loop (i,0,k)
		dis[1<<i][imp[i]] = 0;
	Loop (msk,1,1<<k)
		dij(msk);
	ll ans = inf;
	Loop (v,0,n)
		ans = min(ans, dis[(1<<k)-1][v]);
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Incorrect 2 ms 2812 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1572 ms 24412 KB Output is correct
2 Correct 1253 ms 27884 KB Output is correct
3 Correct 835 ms 21656 KB Output is correct
4 Correct 82 ms 15048 KB Output is correct
5 Correct 730 ms 25500 KB Output is correct
6 Correct 76 ms 14896 KB Output is correct
7 Correct 7 ms 2948 KB Output is correct
8 Correct 5 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 2908 KB Output is correct
2 Incorrect 10 ms 3028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2858 ms 30668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5003 ms 43176 KB Output is correct
2 Incorrect 5467 ms 47436 KB Output isn't correct
3 Halted 0 ms 0 KB -