This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pid pair<int,double>
#define pld pair<ll,double>
#define pdi pair<double,int>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define bpc __builtin_popcount
#define inf 0x3F3F3F3F
#define infll 0x3F3F3F3F3F3F3F3FLL
#define print(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout<<endl;
double solve(int n, int m, int K, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr)
{
K = min(K, 70);
vector<vector<pid>> adj(n);
for (ll i = 0; i < m; i++)
{
adj[x[i]].pb(mpr(y[i], c[i]));
adj[y[i]].pb(mpr(x[i], c[i]));
}
vector<vector<double>> dist(n, vector<double> (K + 1, -1));
priority_queue< pair<double, pii>, vector< pair<double, pii> >, greater< pair<double, pii> > > pq;
vector<int> u(n, 0);
u[0] = 1;
queue<int> q;
while (!q.empty())
{
int f = q.front();
q.pop();
for (pid &v : adj[f])
{
if (u[v.fi]) continue;
u[v.fi] = 1;
q.push(v.fi);
}
}
for (int i = 0; i < n; i++)
{
if (u[i] && (!i || arr[i] == 0))
{
dist[i][0] = 0;
pq.push(mpr(0, mpr(0, i)));
}
}
while (!pq.empty())
{
double d = pq.top().fi;
int k = pq.top().se.fi;
int from = pq.top().se.se;
pq.pop();
if (from == h) continue;
if (d > dist[from][k]) continue;
for (int i = 0; i < adj[from].size(); i++)
{
int to = adj[from][i].fi;
double w = adj[from][i].se;
if (arr[to] == 1 || arr[to] == 2)
{
if (dist[to][k] > d + w || dist[to][k] == -1)
{
dist[to][k] = d + w;
pq.push(mpr(dist[to][k], mpr(k, to)));
}
}
if (k < K && arr[to] == 2)
{
if (dist[to][k + 1] > (d + w)/2 || dist[to][k + 1] == -1)
{
dist[to][k + 1] = (d + w)/2;
pq.push(mpr(dist[to][k + 1], mpr(k + 1, to)));
}
}
}
}
double res = -1;
for (int i = 0; i <= K; i++)
{
if (dist[h][i] == -1) continue;
if (res == -1) res = dist[h][i];
else res = min(res, dist[h][i]);
}
return res;
}
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:70:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int i = 0; i < adj[from].size(); i++)
| ~~^~~~~~~~~~~~~~~~~~
# | 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... |