답안 #107688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107688 2019-04-25T13:01:06 Z Kepperoni Cities (BOI16_cities) C++14
74 / 100
6000 ms 245852 KB
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

const int MAXN = 1e5 + 10;

ll n, m, kk;
vector<pii> k[MAXN];

ll di[MAXN][40];

int main(){
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> n >> kk >> m;
	for(int i=0; i<=n; i++)
		for(int j=0; j<40; j++)
			di[i][j] = 1e16;
	
	priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> q;
	for(int i=0; i<kk; i++){
		int cu; cin >> cu;
		di[cu][1<<i] = 0;
		q.push({0, {cu, 1<<i}});
	}

	for(int i=0; i<m; i++){
		ll fr, to, co; cin >> fr >> to >> co;
		k[fr].pb({to, co});
		k[to].pb({fr, co});
	}

	while(!q.empty()){
		auto x = q.top();
		q.pop();

		//cout << x.y.x << " " << bitset<3>(x.y.y) << " " << x.x << endl;

		if(x.x > di[x.y.x][x.y.y]) continue;
		for(auto u : k[x.y.x]){
			if(di[u.x][x.y.y] > x.x + u.y){
				di[u.x][x.y.y] = x.x + u.y;
				q.push({x.x+u.y, {u.x, x.y.y}});
			}
		}

		for(int i=1; i<(1<<kk); i++){
			if((i & x.y.y) == 0){
				//cout << i << " " << x.y.y << endl;
				int nm = i | x.y.y;
				if(di[x.y.x][nm] > x.x + di[x.y.x][i]){
					di[x.y.x][nm] = x.x + di[x.y.x][i];
					q.push({di[x.y.x][nm], {x.y.x, nm}});
				}
			}
		}
	}

	ll ans = 1e16;
	for(int i=1; i<=n; i++)
		ans = min(ans, di[i][(1<<kk)-1]);
	
	cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 5 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1432 ms 73336 KB Output is correct
2 Correct 1177 ms 60460 KB Output is correct
3 Correct 635 ms 47716 KB Output is correct
4 Correct 100 ms 16128 KB Output is correct
5 Correct 574 ms 54900 KB Output is correct
6 Correct 98 ms 15788 KB Output is correct
7 Correct 9 ms 3456 KB Output is correct
8 Correct 8 ms 3200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 4092 KB Output is correct
2 Correct 13 ms 3648 KB Output is correct
3 Correct 10 ms 3456 KB Output is correct
4 Correct 11 ms 3520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3923 ms 97988 KB Output is correct
2 Correct 3172 ms 97452 KB Output is correct
3 Correct 2193 ms 66304 KB Output is correct
4 Correct 2048 ms 82476 KB Output is correct
5 Correct 459 ms 30980 KB Output is correct
6 Correct 135 ms 18316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6107 ms 245852 KB Time limit exceeded
2 Halted 0 ms 0 KB -