Submission #1131122

#TimeUsernameProblemLanguageResultExecution timeMemory
1131122AnhPhamCyberland (APIO23_cyberland)C++20
0 / 100
20 ms3260 KiB
#include <bits/stdc++.h>
#include "cyberland.h"

using namespace std;

// #define int     long long
#define sz(v)   (int)(v).size()
#define all(v)  (v).begin(), (v).end()

const   int     INF = (int)1e18 + 18;

struct EDGE {
    int x, y, c;
};

int N, M, K, H;
vector <EDGE> edge;
vector <int> A;

namespace sub1 {
    bool check_condition() {
        return N <= 3 && K <= 30;
    }

    double solve() {
        if (N == 1)
            return 0.0;
        else {
            vector <vector <double>> cost(N, vector <double> (N, INF));
            for (auto [u, v, c] : edge)
                cost[u][v] = cost[v][u] = c;

            if (N == 2)
                return (cost[0][H] >= INF ? -1 : cost[0][H]);
            else {
                double ret = cost[0][H];
                int other = 3 - H;
                if (cost[0][other] >= INF && cost[other][H] >= INF)
                    return -1.0;
                else {
                    if (A[other] == 0)
                        ret = min(ret, cost[other][H]);
                    else if (A[other] == 1)
                        ret = min(ret, cost[0][other] + cost[other][H]);
                    else {
                        if (K >= 1)
                            ret = min(ret, cost[0][other] / 2.0 + cost[other][H]);
                        else
                            ret = min(ret, cost[0][other] + cost[other][H]);
                    }
                }

                return ret;
            }
        }
    }
}

double solve(int n, int m, int k, int h, vector <int> X, vector <int> Y, vector <int> C, vector <int> arr) {
    N = n, M = m, K = k, H = h;
    A = arr;
    for (int i = 0; i < M; ++i)
        edge.push_back({ X[i], Y[i], C[i] });
    
    if (sub1 :: check_condition())
        sub1 :: solve();

    return -1;
}
#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...