제출 #1153131

#제출 시각아이디문제언어결과실행 시간메모리
1153131TroySer사이버랜드 (APIO23_cyberland)C++20
8 / 100
47 ms15172 KiB
#include <bits/stdc++.h>
#include "cyberland.h"
#include <vector>

using namespace std;
using ll = long long;

const ll INF = 1e18;

vector<vector<ll> > adjList;
map<pair<ll, ll>, ll> weightMat;

vector<double> memo;
vector<bool> visited;

double DP(ll currentNode, ll N, ll H) {

    // cout << currentNode << " " << numSpecialsLeft << endl;

    if (currentNode == H) {
        return 0.0;
    }

    if (visited[currentNode]) {
        return memo[currentNode];
    }

    visited[currentNode] = true;

    double minPossible = (double)INF;
    for (ll v: adjList[currentNode]) { // currentNode -> v
        minPossible = min(minPossible, DP(v, N, H) + (double)weightMat[{currentNode, v}]);
    }

    return memo[currentNode] = minPossible;

}

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {

    adjList.clear();
    weightMat.clear();

    adjList.resize(N);
    // weightMat.resize(N, vector<ll>(N, INF));

    for (ll i = 0; i < M; i++) {
        adjList[x[i]].push_back(y[i]);
        adjList[y[i]].push_back(x[i]);
        weightMat[{x[i], y[i]}] = c[i];
        weightMat[{y[i], x[i]}] = c[i];
    }

    visited.clear();
    memo.clear();
    visited.resize(N, false);
    memo.resize(N, INF);

    double response = DP(0, N, H);

    if (response >= INF) {
        return -1.0;
    } else {
        return response;
    }

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...