답안 #253854

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253854 2020-07-28T22:58:58 Z super_j6 Cities (BOI16_cities) C++14
15 / 100
449 ms 41668 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
#include <set>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<ll, ll>
#define f first
#define s second

ll inf = 0x3f3f3f3f3f3f3f3f;
const int mxn = 1000;
int n, m, k;
int a[mxn];
ll d[mxn][mxn];
vector<pi> g[mxn];
set<pi> pq;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k >> m;
	
	for(int i = 0; i < k; i++){
		cin >> a[i];
		a[i]--;
	}

	for(int i = 0; i < m; i++){
		int u, v, w;
		cin >> u >> v >> w;
		u--, v--;
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}
	
	memset(d, inf, sizeof(d));
	for(int s = 0; s < n; s++){
		d[s][s] = 0;
		pq.insert({0, s});
		while(!pq.empty()){
			int c = pq.begin()->s;
			pq.erase(pq.begin());
			for(pi i : g[c]){
				if(d[s][c] + i.s < d[s][i.f]){
					pq.erase({d[s][c], i.f});
					pq.insert({d[s][i.f] = d[s][c] + i.s, i.f});
				}
			}
		}
	}
	
	ll ret = inf;
	for(int i = 0; i < n; i++)
	for(int j = 0; j < n; j++)
	for(int l = 0; l < (1 << k); l++){
		ll cur = d[i][j];
		for(int p = 0; p < k; p++){
			cur += d[a[p]][((l >> p) & 1) ? i : j];
		}
		ret = min(ret, cur);
	}
	
	cout << ret << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8192 KB Output is correct
2 Correct 6 ms 8192 KB Output is correct
3 Correct 6 ms 8192 KB Output is correct
4 Correct 6 ms 8192 KB Output is correct
5 Incorrect 7 ms 8192 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 159 ms 41668 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 414 ms 8320 KB Output is correct
2 Correct 449 ms 8440 KB Output is correct
3 Correct 221 ms 8320 KB Output is correct
4 Correct 133 ms 8320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 152 ms 41592 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 155 ms 41592 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -