Submission #107693

# Submission time Handle Problem Language Result Execution time Memory
107693 2019-04-25T13:26:54 Z Kepperoni Cities (BOI16_cities) C++14
74 / 100
6000 ms 78720 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];
bool vis[MAXN][40];

int main(){
	ios_base::sync_with_stdio(false), cin.tie(0), cout.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;
	queue<pii> q;
	for(int i=0; i<kk; i++){
		int cu; cin >> cu;
		di[cu][1<<i] = 0;
		q.push({cu, 1<<i});
		vis[cu][1<<i] = 1;
	}

	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.front();
		q.pop();
		vis[x.x][x.y] = 0;
		ll cdi = di[x.x][x.y];

		//cout << x.y.x << " " << bitset<3>(x.y.y) << " " << x.x << endl;
		int oma = ~x.y;
		int i = 0;
		while(i < (1<<kk)){
			int a = i ^ oma;				
			a = a & -a;
			i ^= a;
			i &= -a;
			//cout << i << " " << x.y.y << endl;
			int nm = i | x.y;
			if(di[x.x][nm] > cdi + di[x.x][i]){
				di[x.x][nm] = cdi + di[x.x][i];
				if(!vis[x.x][nm]){
					vis[x.x][nm] = 1;
					q.push({x.x, nm});
				}
			}
		}

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

	}

	ll ans = 1e16;
	for(int i=1; i<=n; i++)
		ans = min(ans, di[i][(1<<kk)-1]);
	
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 5 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1204 ms 54272 KB Output is correct
2 Correct 1093 ms 53848 KB Output is correct
3 Correct 269 ms 43156 KB Output is correct
4 Correct 153 ms 11848 KB Output is correct
5 Correct 528 ms 50696 KB Output is correct
6 Correct 98 ms 11644 KB Output is correct
7 Correct 7 ms 3200 KB Output is correct
8 Correct 7 ms 3200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3328 KB Output is correct
2 Correct 9 ms 3328 KB Output is correct
3 Correct 7 ms 3072 KB Output is correct
4 Correct 9 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3177 ms 61796 KB Output is correct
2 Correct 2376 ms 62100 KB Output is correct
3 Correct 466 ms 43256 KB Output is correct
4 Correct 1716 ms 39564 KB Output is correct
5 Correct 414 ms 17500 KB Output is correct
6 Correct 145 ms 13944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6013 ms 78720 KB Time limit exceeded
2 Halted 0 ms 0 KB -