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;
struct Arista
{
int v, p;
};
struct Nodo
{
vector <Arista> ady;
int ability;
};
vector <Nodo> g;
vector <Arista> padre;
vector <bool> vis;
int h;
bool alcanzado;
void clean(int N)
{
g.clear();
padre.clear();
alcanzado = false;
vis.clear();
g.resize(N);
padre.resize(N);
vis.resize(N, false);
}
void dfs(int nodo, int pe)
{
if (nodo == h)
{
alcanzado = true;
return;
}
for (auto i : g[nodo].ady)
{
if (!vis[i.v])
{
padre[i.v] = {nodo, i.p};
vis[i.v] = true;
dfs(i.v, nodo);
}
}
}
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)
{
h = H;
clean(N);
for (int i = 0; i < M; i++)
{
g[x[i]].ady.push_back({y[i], c[i]});
g[y[i]].ady.push_back({x[i], c[i]});
}
for (int i = 0; i < N; i++)
{
g[i].ability = arr[i];
}
vis[0] = true;
padre[0] = {-1, 0};
dfs(0, 0);
if (alcanzado)
{
int cost = 0;
int curr = H;
while (curr != -1)
{
cost += padre[curr].p;
curr = padre[curr].v;
}
return cost;
}
return -1;
}
/*
if (N <= 3)
{
if (N == 2)
{
for (auto i : g[0].ady)
{
if (i.v == H)
{
return i.p;
}
}
return -1;
}
double minH = 1e9 + 10;
bool alcanzado = false;
double cost = 0;
int aux = -1;
double caux = 0;
for (auto i : g[0].ady)
{
if (i.v == H)
{
alcanzado = true;
minH = min(minH, (double)cost + i.p);
}else
{
aux = i.v;
caux = (double) i.p;
}
}
if (aux != -1)
{
for(auto i : g[aux].ady)
{
if (i.v != 0)
{
alcanzado = true;
if (g[aux].ability == 0)
{
minH = min((double)i.p, minH);
}
if (g[aux].ability == 2)
{
minH = min((double)i.p + (double)(caux/(double)2), minH);
}
}
}
}
if (!alcanzado)
{
return -1;
}else
{
return minH;
}
}
*/
# | 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... |