# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
27467 | top34051 | Cities (BOI16_cities) | C++14 | 4000 ms | 235020 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
#define inf (long long)1e16
struct node {
int x,bit;
long long val;
node(int _x = 0,int _bit = 0,long long _val = 0) {
x = _x; bit = _bit; val = _val;
}
bool operator < (node a) const {
return a.val<val;
}
};
int n,k,m;
int p2[10];
int sp[maxn];
long long mem[maxn][35];
vector<pair<int,int> > from[maxn];
priority_queue<node> heap;
main() {
int i,x,y,val,bit;
node t;
scanf("%d%d%d",&n,&k,&m);
for(i=1;i<=n;i++) sp[i] = -1;
for(i=0;i<k;i++) scanf("%d",&x), sp[x] = i;
while(m--) {
scanf("%d%d%d",&x,&y,&val);
from[x].push_back({y,val}); from[y].push_back({x,val});
}
p2[-1] = 0; p2[0] = 1;
for(i=1;i<=k;i++) p2[i] = p2[i-1]*2;
for(x=1;x<=n;x++) {
for(bit=0;bit<p2[k];bit++) mem[x][bit] = inf;
if(sp[x]!=-1) {
mem[x][p2[sp[x]]] = 0;
heap.push(node(x,p2[sp[x]],0));
}
}
while(!heap.empty()) {
t = heap.top(); heap.pop();
if(t.bit==p2[k]-1) {
printf("%lld",t.val);
return 0;
}
for(bit=0;bit<p2[k];bit++) {
if(mem[t.x][t.bit|bit] > mem[t.x][t.bit] + mem[t.x][bit]) {
mem[t.x][t.bit|bit] = mem[t.x][t.bit] + mem[t.x][bit];
heap.push(node(t.x,t.bit|bit,mem[t.x][t.bit|bit]));
}
}
for(i=0;i<from[t.x].size();i++) {
y = from[t.x][i].first; val = from[t.x][i].second;
if(mem[y][t.bit|p2[sp[y]]] > mem[t.x][t.bit] + val) {
mem[y][t.bit|p2[sp[y]]] = mem[t.x][t.bit] + val;
heap.push(node(y,t.bit|p2[sp[y]],mem[y][t.bit|p2[sp[y]]]));
}
}
}
}
컴파일 시 표준 에러 (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... |