이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
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);
}
}
void clr() {
for (int i = 0; i < n; ++i) {
g[i].clear();
used[i] = 0;
}
}
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 < m; ++i) {
g[x[i]].pub({ y[i],c[i] });
g[y[i]].pub({ x[i],c[i] });
}
dfs();
if (!used[h]) {
clr();
return -1;
}
db mx = 1000000000000000000;
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 (d[u][kx] < dist) continue;
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]);
clr();
return ans;
}
# | 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... |