This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <cassert>
#include <fstream>
#include "cyberland.h"
using namespace std;
mt19937 rnd(7069);
typedef int itn;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef float fl;
typedef long double ld;
using vi = vector<int>;
using vll = vector<ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mpr make_pair
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define all(x) (x).begin(), (x).end()
#define USACO freopen("feast.in", "r", stdin); freopen("feast.out", "w", stdout);
const int MAX = int(2e9 + 5);
const ll MAXL = ll(1e18) + 5ll;
const ll MOD = ll(1000000007);
const ll MOD2 = ll(998244353);
const int N = 100005, M = 40;
db d[N][M];
int used[N], clr[N][M];
vector<pair<int, db>> g[N];
int n, m, k, h;
void dfs(int u = 0) {
used[u] = 1;
for (auto to : g[u]) {
if (!used[to.ff]) dfs(to.ff);
}
}
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) {
n = N, k = K, m = M, h = H;
for (int i = 0; i < n; ++i) {
used[i] = 0;
for (int j = 0; j <= 30; ++j) {
clr[i][j] = 0;
}
g[i].clear();
}
for (int i = 0; i < m; ++i) {
g[x[i]].pub({ y[i],c[i] });
g[y[i]].pub({ x[i],c[i] });
}
dfs();
if (!used[h]) {
return -1;
}
db mx = 1e18;
priority_queue<pair<db, pii>> pq;
for (int i = 0; i < n; ++i) {
if (arr[i] == 0 || i == 0) {
pq.push({ 0,{i,0} });
for (int j = 0; j <= k; ++j) {
d[i][j] = 0;
}
}
else {
for (int j = 0; j <= k; ++j) {
d[i][j] = mx;
}
}
}
while (!pq.empty()) {
db dist = -pq.top().ff;
int u = pq.top().ss.ff, kx = pq.top().ss.ss;
pq.pop();
if (clr[u][kx]) continue;
clr[u][kx] = 1;
for (auto tox : g[u]) {
int to = tox.ff;
db dx = tox.ss;
if (!arr[to]) continue;
if (d[u][kx] + dx < d[to][kx]) {
d[to][kx] = d[u][kx] + dx;
pq.push({ -d[to][kx],{to,kx} });
}
if (kx < k && arr[to] == 2 && (d[u][kx] + dx) / 2 < d[to][kx + 1]) {
d[to][kx + 1] = (d[u][kx] + dx) / 2;
pq.push({ -d[to][kx + 1],{to,kx + 1} });
}
}
}
db ans = mx;
for (int j = 0; j <= k; ++j) ans = min(ans, d[h][j]);
return ans;
}
Compilation message (stderr)
cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:102:12: warning: unused variable 'dist' [-Wunused-variable]
102 | db dist = -pq.top().ff;
| ^~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |