# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
776264 | Sharky | 사이버랜드 (APIO23_cyberland) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const double INF = 1E18;
struct node {
double di;
int u, k;
bool operator < (const node& o) const {
if (k != o.k) return k > o.k;
return di > o.di;
}
};
double solve(int32_t N, int32_t M, int32_t K, int32_t H, std::vector<int32_t> x, std::vector<int32_t> y, std::vector<int32_t> c, std::vector<int32_t> arr) {
K = min(K, 80);
vector<pair<int, int>> adj[N];
vector<vector<double>> d(N, vector<double> (K + 1, INF));
for (int i = 0; i < M; i++) {
if (x[i] != H) adj[x[i]].push_back({y[i], c[i]});
if (y[i] != H) adj[y[i]].push_back({x[i], c[i]});
}
queue<int> q;
vector<bool> vis(N, 0);
vis[0] = 1;
q.push(0);
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto& [v, w] : adj[u]) {
if (!vis[v]) {
vis[v] = true;
q.push(v);
}
}
}
priority_queue<node> pq;
pq.push({0.0, 0, 0});
d[0][0] = 0.0;
for (int i = 0; i < N; i++) if (arr[i] == 0 && vis[i]) {
pq.push({0.0, i, 0});
d[i][0] = 0.0;
}
while (!pq.empty()) {
auto [di, u, k] = pq.top();
pq.pop();
if (di != d[u][k]) continue;
for (auto& [v, w] : adj[u]) {
double new_weight = d[u][k] + w;
if (d[v][k] > new_weight) {
d[v][k] = new_weight;
pq.push((node) {d[v][k], v, k});
}
if (arr[v] == 2 && k != K) {
double new_weight = d[u][k] + w;
new_weight /= 2.0;
if (d[v][k + 1] > new_weight) {
d[v][k + 1] = new_weight;
pq.push((node) {d[v][k + 1], v, k + 1});
}
}
}
}
double res = *min_element(d[H].begin(), d[H].end());
if (res >=#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const double INF = 1E18;
struct node {
double di;
int u, k;
bool operator < (const node& o) const {
if (k != o.k) return k > o.k;
return di > o.di;
}
};
double solve(int32_t N, int32_t M, int32_t K, int32_t H, std::vector<int32_t> x, std::vector<int32_t> y, std::vector<int32_t> c, std::vector<int32_t> arr) {
K = min(K, 80);
vector<pair<int, int>> adj[N];
vector<vector<double>> d(N, vector<double> (K + 1, INF));
for (int i = 0; i < M; i++) {
if (x[i] != H) adj[x[i]].push_back({y[i], c[i]});
if (y[i] != H) adj[y[i]].push_back({x[i], c[i]});
}
queue<int> q;
vector<bool> vis(N, 0);
vis[0] = 1;
q.push(0);
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto& [v, w] : adj[u]) {
if (!vis[v]) {
vis[v] = true;
q.push(v);
}
}
}
priority_queue<node> pq;
pq.push({0.0, 0, 0});
d[0][0] = 0.0;
for (int i = 0; i < N; i++) if (arr[i] == 0 && vis[i]) {
pq.push({0.0, i, 0});
d[i][0] = 0.0;
}
while (!pq.empty()) {
auto [di, u, k] = pq.top();
pq.pop();
if (di != d[u][k]) continue;
for (auto& [v, w] : adj[u]) {
double new_weight = d[u][k] + w;
if (d[v][k] > new_weight) {
d[v][k] = new_weight;
pq.push((node) {d[v][k], v, k});
}
if (arr[v] == 2 && k != K) {
double new_weight = d[u][k] + w;
new_weight /= 2.0;
if (d[v][k + 1] > new_weight) {
d[v][k + 1] = new_weight;
pq.push((node) {d[v][k + 1], v, k + 1});
}
}
}
}
double res = *min_element(d[H].begin(), d[H].end());
if (res >= INF) return -1;
return res;
} INF) return -1;
return res;
}