# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
62050 | Crown | Cities (BOI16_cities) | C++14 | 262 ms | 44956 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector< ii > vii;
const int maxn = 1e5+5;
const int maxk = 5;
vii adj[maxn];
int n, k, m;
int imp[maxk+5];
ll dist[(1<<5)+5][maxn];
int mark[maxn];
struct node
{
int bit, u;
ll d;
node(int _bit, int _u, ll _d)
{
bit = _bit; u = _u; d = _d;
}
bool operator < (node other) const
{
return d> other.d;
}
};
int main()
{
memset(mark, -1, sizeof mark);
scanf("%d %d %d", &n, &k, &m);
for(int i = 0; i< k; i++)
{
scanf("%d", imp+i);
mark[imp[i]] = i;
}
for(int i = 1; i<= m; i++)
{
int u, v, w; scanf("%d %d %d", &u, &v, &w);
adj[u].pb(ii(v, w));
adj[v].pb(ii(u, w));
}
memset(dist, 32, sizeof dist);
priority_queue<node> pq;
for(int i = 1; i<= n; i++)
{
dist[0][i] = 0;
pq.push(node(0, i, 0));
}
for(int i = 0; i< k; i++)
{
dist[1<<i][imp[i]] = 0;
pq.push(node(1<<i, imp[i], 0));
}
while(!pq.empty())
{
node x = pq.top(); pq.pop();
int bit = x.bit, u = x.u;
ll d = x.d;
if(d> dist[bit][u]) continue;
for(auto edge : adj[u])
{
int v = edge.X, w = edge.Y;
if(d+w < dist[bit][v])
{
dist[bit][v] = d+w;
for(int comp = 0; comp< (1<<k); comp++)
{
if(dist[bit|comp][v]> dist[bit][v]+dist[comp][v])
{
dist[bit|comp][v] = dist[bit][v]+dist[comp][v];
pq.push(node(bit|comp, v, dist[bit|comp][v]));
}
}
}
}
}
ll best = 1e18;
for(int i = 1; i<= n; i++) best = min(best, dist[(1<<k)-1][i]);
printf("%lld\n", best);
}
컴파일 시 표준 에러 (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... |