제출 #1152994

#제출 시각아이디문제언어결과실행 시간메모리
1152994tapilyoca사이버랜드 (APIO23_cyberland)C++20
0 / 100
17 ms6212 KiB
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using ld = long double;


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) {
    
    vector<vector<pair<ll,ll>>> adj(N+1);
    for(int i = 0; i < M; i++){
        ll a = x[i];
        ll b = y[i];
        ll w = c[i];
        adj[a].push_back({b,w});
        adj[b].push_back({a,w});
    }


    // first BFS: check which 0s we can actually reach
    vector<bool> works(N+1,0);
    vector<bool> vis(N+1,0);

    vis[0] = 1;
    queue<ll> q;
    q.push(0);
    while(!q.empty()){
        ll at = q.front();
        q.pop();
        for(pair<ll,ll> p : adj[at]){
            ll node = p.first;
            if(vis[node]) continue;
            if(node == H) continue;

            vis[node] = 1;
            works[node] = 1;
            q.push(node);
        }
    }

    vis.clear();
    queue<pair<ll,ll>> qq;

    ll mn = 1e18;

    vis[H] = 1;
    qq.push({H,0});
    while(!qq.empty()){
        pair<ll,ll> temp = qq.front();
        qq.pop();
        ll at = temp.first;
        ll dist = temp.second;
    
        for(pair<ll,ll> edge : adj[at]){
            if(vis[edge.first]) continue;
            vis[edge.first] = 1;
        
            if((arr[edge.first] == 0 and works[edge.first]) or edge.first == 0){
                mn = min(dist+edge.second, mn);
            }

            qq.push({edge.first, edge.second+dist});
        }
    }

    return mn;
    
    // 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...