이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using node = pair<int, ll>;
vector<vector<node>> g;
set<int> st;
vector<int> used;
void dfs(int u, int p){
if(u == p) return;
used[u] = 1;
for(auto [v, w]: g[u])
if(!used[v])
dfs(v, p);
}
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) {
for(int x: arr) assert(x < 2);
used.assign(N, 0);
g.assign(N, vector<node>());
vector<ll> h(N, 1e18);
for(int i = 0; i < M; ++i){
g[x[i]].emplace_back(y[i], c[i]);
g[y[i]].emplace_back(x[i], c[i]);
}
dfs(0, H);
priority_queue<node, vector<node>, greater<node>> b;
b.emplace(H, 0);
while(!b.empty()){
auto [u, cur] = b.top();
b.pop();
if(h[u] < cur) continue;
h[u] = cur;
for(auto [v, w]: g[u])
b.emplace(v, cur+w);
}
ll ans = 1e18;
for(int i = 0; i < N; ++i)
if(arr[i] == 0 && used[i] == 1)
ans = min(ans, h[i]);
return (ans == 1e18 ? -1 : ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |