# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
531440 | Yazan_Alattar | Cities (BOI16_cities) | C++14 | 2185 ms | 48708 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 100007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;
vector < pair <int,ll> > adj[M];
int n, k, m, city[10];
ll dp[70][M];
int main(){
scanf("%d%d%d", &n, &k, &m);
for(int i = 1; i <= k; ++i) scanf("%d", &city[i]);
for(int i = 1; i <= m; ++i){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
adj[a].pb({b, c});
adj[b].pb({a, c});
}
for(int mask = 0; mask < (1 << k); ++mask) for(int i = 1; i <= n; ++i) dp[mask][i] = inf;
for(int i = 1; i <= k; ++i) dp[(1 << (i - 1))][city[i]] = 0;
for(int mask = 1; mask < (1 << k); ++mask){
priority_queue < pair <ll,int> > q;
for(int i = 1; i <= n; ++i) if(dp[mask][i] != inf) q.push({-dp[mask][i], i});
while(!q.empty()){
int node = q.top().S;
ll cost = -q.top().F;
q.pop();
if(cost != dp[mask][node]) continue;
for(auto i : adj[node]) if(cost + i.S < dp[mask][i.F]){
dp[mask][i.F] = cost + i.S;
q.push({-cost -i.S, i.F});
}
}
for(int mask2 = 1; mask2 < (1 << k); ++mask2) if((mask & mask2) == 0)
for(int i = 1; i <= n; ++i)
dp[(mask2 | mask)][i] = min(dp[(mask2 | mask)][i], dp[mask][i] + dp[mask2][i]);
}
ll ans = inf;
for(int i = 1; i <= n; ++i) ans = min(ans, dp[(1 << k) - 1][i]);
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |