답안 #945964

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945964 2024-03-14T09:10:00 Z phoenix0423 Cities (BOI16_cities) C++17
52 / 100
6000 ms 247096 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][40];
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";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4704 KB Output is correct
2 Correct 1 ms 4696 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 4728 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1033 ms 74924 KB Output is correct
2 Correct 919 ms 73240 KB Output is correct
3 Correct 368 ms 47708 KB Output is correct
4 Correct 158 ms 18644 KB Output is correct
5 Correct 391 ms 56324 KB Output is correct
6 Correct 135 ms 17748 KB Output is correct
7 Correct 5 ms 5144 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 5720 KB Output is correct
2 Correct 10 ms 5724 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 8 ms 5928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3129 ms 149296 KB Output is correct
2 Correct 2835 ms 146568 KB Output is correct
3 Correct 1342 ms 66272 KB Output is correct
4 Correct 2075 ms 83628 KB Output is correct
5 Correct 490 ms 45564 KB Output is correct
6 Correct 245 ms 23776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6007 ms 247096 KB Time limit exceeded
2 Halted 0 ms 0 KB -