답안 #976552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976552 2024-05-06T17:23:24 Z Elliot_7002 사이버랜드 (APIO23_cyberland) C++17
0 / 100
24 ms 10692 KB
#include <iostream>
#include <bits/stdc++.h> 
using namespace std;
#define INF 1e9
vector<vector<pair<int,int>>> adj;
vector<double> distances;
vector<bool> visited;
priority_queue<int> q;
void dijkstra(int source)
{
    visited[source] = true;
    distances[source] = 0;
    q.push(source);
    while(!q.empty()){
        int a = q.top();
        q.pop();
        if(visited[a]){
            continue;
        }
        for(auto neigh: adj[a]){
            if(distances[a] + neigh.second < distances[neigh.first]){
                distances[neigh.first] = distances[a] + neigh.second;
                q.push(neigh.second);
            }
        }
    }
}
bool dfs_hunt(int node, int target){
    bool found = false;
    if(visited[node]){
        return found;
    }
    if(node == target){
        found = true;
        return found;
    }
    for(auto i : adj[node]){
        found = dfs_hunt(i.first,target);
        if(found){
            return found;
        }
    }
    return found;

    
}
double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){
    adj.clear();
    adj.resize(n);
    visited.clear();
    visited.resize(n,false);
    for(int i = 0; i < m ;i++){
        adj[x[i]].push_back({y[i],c[i]});
        adj[y[i]].push_back({x[i],c[i]});
    }
    for(int i = 0; i < n; i++){
        distances[i] = INF;
    }
    if(!dfs_hunt(0, h)){
        return -1;
    }
    else{
        visited.clear();
        visited.resize(n,false);
        dijkstra(h);
        int mini = INF;
        for(int i = 0; i < n; i++){
            if(arr[i] == 0){
                if(distances[i] < mini){
                    mini = distances[i];
                }
            }
        }
        return mini;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 10692 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 708 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -