# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
982070 | alo_54 | 사이버랜드 (APIO23_cyberland) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
struct Arista
{
int v, p;
};
struct Nodo
{
vector <Arista> ady;
int ability;
int idx;
int cost0, costP = 0;
};
vector <Nodo> g;
vector <Arista> padre;
vector <bool> vis;
int h;
void clean(int N)
{
g.clear();
padre.clear();
vis.clear();
g.resize(N);
padre.resize(N);
vis.resize(N, false);
}
void dfs(int nodo)
{
if (nodo == h)
{
return;
}
for (auto i : g[nodo].ady)
{
if (!vis[i.v])
{
padre[i.v] = {nodo, i.p};
//cout<<"padre "<<i.v<<": "<<nodo<<" c: "<<i.p<<endl;
vis[i.v] = true;
dfs(i.v);
}
}
}
struct Estado
{
int p;
int idx;
};
struct Comp
{
bool operator() (Estado a, Estado b) const
{
return a.p > b.p;
}
};
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr)
{
h = H;
clean(N);
for (int i = 0; i < M; i++)
{
g[x[i]].ady.push_back({y[i], c[i]});
g[y[i]].ady.push_back({x[i], c[i]});
}
for (int i = 0; i < N; i++)
{
g[i].ability = arr[i];
g[i].idx = i;
}
///////////dijkstra desde los 0's
priority_queue <Estado, vector <Estado>, Comp> pq;
vector <bool> assigned(N, false);
for (auto i : g)
{
if (i.ability == 0)
{
assigned[i.idx] = true;
pq.push({0, i.idx});
g[i.idx].cost0 = 0;
}
}
while (!pq.empty())
{
Estado curr = pq.top();
pq.pop();
if (!assigned[curr.idx])
{
g[curr.idx].cost0 = g[curr.idx].costP;
assigned[curr.idx] = true;
for (auto i : g[curr.idx].ady)
{
g[i.v].costP = min(g[i.v].costP, curr.p+ i.p);
pq.push({g[i.v].costP, i.v});
}
}
}
////////////
vis[0] = true;
padre[0] = {-1, 0};
dfs(0);
int curr = H;
vector <Arista> camino(N);
while (curr != -1)
{
camino[padre[curr].v].v = curr;
camino[padre[curr].v].p = padre[curr].p;
curr =(double) padre[curr].v;
}
double cost = 0;
curr = 0;
while (curr != h)
{
cost = min(cost, (double) g[curr].cost0);
cost += (double)camino[curr].p;
curr = camino[curr].v;
}
return (double)cost;
}
int main()
{
int n, m, k, h;
cin>>n>>m>>k>>h;
vector <int> x;
vector <int> y;
vector <int> c;
vector <int> arr;
for (int i = 0; i < m; i++)
{
int a; cin>>a;
x.push_back(a);
}
for (int i = 0; i < m; i++)
{
int a; cin>>a;
y.push_back(a);
}
for (int i = 0; i < m; i++)
{
int a; cin>>a;
c.push_back(a);
}
for (int i = 0; i < n; i++)
{
int s; cin>>s;
arr.push_back(s);
}
double resp = solve(n, m, k, h, x, y, c, arr);
cout<<resp<<"\n";
}
/*
if (N <= 3)
{
if (N == 2)
{
for (auto i : g[0].ady)
{
if (i.v == H)
{
return i.p;
}
}
return -1;
}
double minH = 1e9 + 10;
bool alcanzado = false;
double cost = 0;
int aux = -1;
double caux = 0;
for (auto i : g[0].ady)
{
if (i.v == H)
{
alcanzado = true;
minH = min(minH, (double)cost + i.p);
}else
{
aux = i.v;
caux = (double) i.p;
}
}
if (aux != -1)
{
for(auto i : g[aux].ady)
{
if (i.v != 0)
{
alcanzado = true;
if (g[aux].ability == 0)
{
minH = min((double)i.p, minH);
}
if (g[aux].ability == 2)
{
minH = min((double)i.p + (double)(caux/(double)2), minH);
}
}
}
}
if (!alcanzado)
{
return -1;
}else
{
return minH;
}
}
*/