이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#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 <fstream>
using namespace std;
/* -------------------- Typedefs -------------------- */
typedef int itn;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef float fl;
typedef long double ld;
/* -------------------- Usings -------------------- */
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>;
/* -------------------- Defines -------------------- */
#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()
/* -------------------- Constants -------------------- */
const int MAX = int(2e9 + 5);
const ll MAXL = ll(1e18) + 5ll;
const ll MOD = ll(1e9 + 7);
const ll MOD2 = ll(998244353);
const int N = 100005;
vector<pair<int, ld>> g[N];
vector<ld> d[N];
int n, m, k, h;
int used[N];
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();
d[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, m = M, k = K, h = H;
for (int i = 0; i < m; ++i) {
g[x[i]].pub({ y[i],(ld)c[i] });
g[y[i]].pub({ x[i],(ld)c[i] });
}
dfs();
if (!used[h]) {
clr();
return -1;
}
d[0].resize(k + 1);
d[0][0] = 0;
priority_queue<pair<ld, pii>> pq;
pq.push({ 0,{0,0} });
for (int i = 1; i < n; ++i) {
if (used[i]) d[i].resize(k + 1);
for (int j = 0; j <= k; ++j) d[i][j] = (ld)MAXL;
if (!arr[i]) {
pq.push({ 0,{i,0} });
d[i][0] = 0;
}
}
while (!pq.empty()) {
int u = pq.top().ss.ff;
int ind = pq.top().ss.ss;
ld w = -pq.top().ff;
pq.pop();
if (w > d[u][ind]) continue;
for (auto to : g[u]) {
if (d[to.ff][ind] > d[u][ind] + to.ss) {
d[to.ff][ind] = d[u][ind] + to.ss;
pq.push({ -d[to.ff][ind],{to.ff,ind} });
}
if (arr[to.ff] == 2 && ind != k) {
if (d[to.ff][ind + 1] > (d[u][ind] + to.ss / (ld)2)) {
d[to.ff][ind + 1] = (d[u][ind] + to.ss / (ld)2);
pq.push({ -d[to.ff][ind + 1],{to.ff,ind + 1} });
}
}
}
}
ld ans = d[h][0];
for (int i = 1; i <= k; ++i) {
ans = min(ans, d[h][i]);
}
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... |