# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
57082 | IvanC | Cities (BOI16_cities) | C++17 | 4680 ms | 67184 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> leve;
typedef pair<ll,int> ii;
typedef tuple<ll,int,int> trinca;
const int MAXN = 1e5 + 10;
const int MAXK = 7;
const int MAXL = 35;
const ll INF = 1e18;
vector<leve> grafo[MAXN];
ll matriz[MAXN][MAXK],menor_distancia[MAXN][MAXL];
int N,K,M,qual[MAXK],processado[MAXN];
int jafoi[MAXN][MAXL];
void Dijkstra(int idx){
memset(processado,0,sizeof(processado));
priority_queue<ii, vector<ii> , greater<ii> > pq;
pq.push(ii(0,qual[idx]));
while(!pq.empty()){
ii davez = pq.top();
pq.pop();
int v = davez.second;
ll path = davez.first;
if(processado[v]) continue;
processado[v] = 1;
matriz[v][idx] = path;
for(ii aresta : grafo[v]){
int u = aresta.first;
ll w = aresta.second;
if(!processado[u]) pq.push(ii(path + w,u));
}
}
}
int main(){
scanf("%d %d %d",&N,&K,&M);
for(int i = 0;i<K;i++){
scanf("%d",&qual[i]);
}
for(int i = 1;i<=M;i++){
int u,v,w;
scanf("%d %d %d",&u,&v,&w);
grafo[u].push_back(leve(v,w));
grafo[v].push_back(leve(u,w));
}
for(int i = 0;i<K;i++) Dijkstra(i);
ll resposta = INF;
int alvo = (1 << K) - 1;
for(int i = 1;i<=N;i++){
for(int bitmask = 0;bitmask <= alvo;bitmask++){
menor_distancia[i][bitmask] = INF;
}
}
for(int i = 1;i<=N;i++){
for(int j = 0;j<K;j++){
menor_distancia[i][(1 << j)] = matriz[i][j];
}
}
for(int bitmask = 1;bitmask < alvo;bitmask++){
priority_queue<ii,vector<ii>,greater<ii>> pq;
for(int i = 1;i<=N;i++){
if(menor_distancia[i][bitmask] != INF) pq.push(ii(menor_distancia[i][bitmask],i));
}
while(!pq.empty()){
ii davez = pq.top();
pq.pop();
ll path = davez.first;
int v = davez.second;
if(jafoi[v][bitmask]) continue;
jafoi[v][bitmask] = 1;
for(leve aresta : grafo[v]){
int u = aresta.first, w = aresta.second;
if(path + w < menor_distancia[u][bitmask]){
menor_distancia[u][bitmask] = path + w;
pq.push(ii(path + w,u));
}
}
}
for(int j = 0;j<K;j++){
if(bitmask & (1 << j)) continue;
int nbitmask = (bitmask) | (1 << j);
for(int i = 1;i<=N;i++){
menor_distancia[i][nbitmask] = min(menor_distancia[i][nbitmask], menor_distancia[i][bitmask] + matriz[i][j] );
}
}
}
for(int i = 1;i<=N;i++) resposta = min(resposta,menor_distancia[i][alvo]);
printf("%lld\n",resposta);
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... |