Submission #945878

# Submission time Handle Problem Language Result Execution time Memory
945878 2024-03-14T08:21:30 Z phoenix0423 Cities (BOI16_cities) C++17
52 / 100
6000 ms 239832 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
#define lowbit(x) x&-x
const int maxn = 1e5 + 5;
const int INF = 1e18;
int dp[maxn][32];
vector<pll> adj[maxn];

struct info{
	int d, pos, st;
	info(){}
	info(int _d, int _pos, int _st) : d(_d), pos(_pos), st(_st){}
	bool operator < (const info& other) const{
		return d < other.d;
	}
	bool operator > (const info& other) const{
		return d > other.d;
	}
};

signed main(void){
	int n, k, m;
	cin>>n>>k>>m;
	vector<int> a(k);
	for(int i = 0; i < k; i++) cin>>a[i], a[i] --;
	for(int i = 0; i < m; i++){
		int a, b, w;
		cin>>a>>b>>w;
		a--, b--;
		adj[a].eb(b, w);
		adj[b].eb(a, w);
	}
	for(int i = 0; i < n; i++){
		for(int j = 1; j < (1 << j); j++) dp[i][j] = INF;
	}
	priority_queue<info, vector<info>, greater<info>> q;
	for(int i = 0; i < k; i++){
		dp[a[i]][(1 << i)] = 0;
		q.push(info(0, a[i], (1 << i)));
	}
	while(!q.empty()){
		auto [d, pos, st] = q.top(); q.pop();
		if(dp[pos][st] != d) continue;
		for(auto [x, w] : adj[pos]){
			for(int i = 0; i < (1 << k); i++){
				if(dp[x][i | st] > dp[x][i] + d + w){
					dp[x][i | st] = dp[x][i] + d + w;
					q.push(info(dp[x][i | st], x, i | st));
				}
			}
		}
	}
	int ans = INF;
	for(int i = 0; i < n; i++) ans = min(ans, dp[i][(1 << k) - 1]);
	cout<<ans<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Incorrect 1 ms 4700 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1190 ms 67424 KB Output is correct
2 Correct 999 ms 67796 KB Output is correct
3 Correct 396 ms 43300 KB Output is correct
4 Correct 160 ms 18612 KB Output is correct
5 Correct 447 ms 50016 KB Output is correct
6 Correct 131 ms 17816 KB Output is correct
7 Correct 5 ms 5148 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 5720 KB Output is correct
2 Correct 10 ms 5724 KB Output is correct
3 Correct 5 ms 4956 KB Output is correct
4 Correct 8 ms 5720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3460 ms 141712 KB Output is correct
2 Correct 3039 ms 141828 KB Output is correct
3 Correct 1392 ms 61612 KB Output is correct
4 Correct 2308 ms 82616 KB Output is correct
5 Correct 522 ms 45752 KB Output is correct
6 Correct 267 ms 22372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6091 ms 239832 KB Time limit exceeded
2 Halted 0 ms 0 KB -