제출 #1158262

#제출 시각아이디문제언어결과실행 시간메모리
1158262lrnnz사이버랜드 (APIO23_cyberland)C++17
0 / 100
29 ms7112 KiB
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
 
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
#define ll long long
#define ld long double
#define ui uint64_t
#define ar array
#define us unordered_set
#define cont(set, element) ((set).find(element) != (set).end())
 
/********* DEBUG *********/
template <typename T>
void outvec(const vector<T>& Z, int hi = INT_MAX) {
    int count = 0;
    for (const T& x : Z) {
        if (count >= hi) break;
        cout << x << ' ';
        count++;
    }
    cout << "\n";
}

// overloaded function for raw arrays
template <typename T, size_t N>
void outvec(const T (&arr)[N], int hi = INT_MAX) {
    int count = 0;
    for (size_t i = 0; i < N; ++i) {
        if (count >= hi) break;
        cout << arr[i] << ' ';
        count++;
    }
    cout << "\n";
}
 
/********* DEBUG *********/

const ll inf = 1e18;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const int mxN = 200005;


// Subtask arr ∈ {0,1}
// DSU, find all possible starting places
// Push all starting nodes to Djikstra


int parent[100005];

int _find(int x){
    if (parent[x] != x)
    parent[x] = _find(parent[x]);

    return parent[x];
}

void _uni(int x, int y){
    x = _find(x);
    y = _find(y);

    parent[x] = y;
}

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
    for (int i = 0; i < N; i++){
        parent[i] = i;
    }
    
    // cost, node
    vector<vector<pair<double, int>>> adj(N);
    priority_queue<pair<double,int>, vector<pair<double,int>>, greater<pair<double,int>>> minheap;
    vector<bool> visited(N, false);
    
    for (int i = 0; i < M; i++){
        adj[x[i]].pb({c[i], y[i]});
        adj[y[i]].pb({c[i], x[i]});
    }
    
    queue<int> q;
    q.push(0);
    
    while (sz(q)){
        int x = q.front(); q.pop();
        
        if (arr[x] == 0){
            minheap.push({0, x});
        }

        visited[x] = true;
        for (auto y : adj[x]){
            if (!visited[y.second])
            q.push(y.second);
        }
    }
    
    for (int i = 0; i < N; i++)
    visited[i] = false;
    
    while (sz(minheap)){
        auto x = minheap.top(); minheap.pop();
        double cst = x.first;
        double nd = x.second;
        
        visited[nd] = true;
        if (nd == H)
        return cst;
        
        for (auto y : adj[nd]){
            if (!visited[y.second]){
                minheap.push({cst + y.first, y.second});
            }
        }
    }
    
    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...