이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i = a;i < b;i++)
#define ll long long
#define ii pair<ll,ll>
#define F first
#define S second
#define pb push_back
priority_queue<ii,vector<ii>,greater<ii> >pq;
bool v[100005] = {0};
ll dist[100005];
vector<vector<ii> >adj;
void dfs(ll idx){
v[idx] = 1;
for(auto x:adj[idx]){
if(!v[x.F]){
dfs(x.F);
}
}
}
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) {
double ans;
adj.assign(n+5,vector<ii>());
f(i,0,n){
v[i] = 0;
dist[i] = 1e18;
}
f(i,0,m){
adj[x[i]].pb(ii(y[i],c[i]));
adj[y[i]].pb(ii(x[i],c[i]));
}
dfs(0);
f(i,0,n){
if((arr[i] == 0 && v[i]) || i == 0){
pq.push(ii(0,i));
dist[i] = 0;
}
}
while(!pq.empty()){
ii f = pq.top();
pq.pop();
ll w = f.F,u = f.S;
if(dist[u] < w){
continue;
}
for(auto x:adj[u]){
if(dist[x.F] > dist[u] + x.S){
dist[x.F] = dist[u] + x.S;
pq.push(ii(dist[x.F],x.F));
}
}
}
ans = dist[h];
if(dist[h] == 1e18){
ans = -1;
}
return 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... |