답안 #253857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253857 2020-07-28T23:08:03 Z super_j6 Cities (BOI16_cities) C++14
29 / 100
6000 ms 67048 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 = 100000;
int n, m, k;
int a[mxn];
vector<ll> d[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});
	}
	
	for(int s = 0; s < n; s++){
		if(k > 3 || count(a, a + k, s)){
			d[s].assign(n, inf);
			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;
	if(k <= 3){
		for(int i = 0; i < n; i++){
			ll cur = 0;
			for(int j = 0; j < k; j++){
				cur += d[a[j]][i];
			}
			ret = min(ret, cur);
		}
	}else{
		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 3 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Incorrect 3 ms 4992 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 438 ms 20856 KB Output is correct
2 Correct 480 ms 26068 KB Output is correct
3 Correct 142 ms 14840 KB Output is correct
4 Correct 90 ms 17144 KB Output is correct
5 Correct 359 ms 24312 KB Output is correct
6 Correct 92 ms 17272 KB Output is correct
7 Correct 6 ms 5248 KB Output is correct
8 Correct 4 ms 5248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 407 ms 13048 KB Output is correct
2 Correct 414 ms 13048 KB Output is correct
3 Correct 201 ms 12920 KB Output is correct
4 Correct 138 ms 7164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6089 ms 67048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6075 ms 66352 KB Time limit exceeded
2 Halted 0 ms 0 KB -