This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<pair<int,int>>> al;
vector<int> nodes;
void dfs(int u, int p, int H, vector<int> &a) {
if (u==H) return;
if (a[u]==0||u==0) nodes.push_back(u);
for (auto v: al[u]) {
if (v.first==p) continue;
dfs(v.first,u,H,a);
}
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> a) {
al.assign(N+1,vector<pair<int,int>>());
nodes.clear();
for (int i=0; i<M; i++) {
al[x[i]].push_back({y[i],c[i]});
al[y[i]].push_back({x[i],c[i]});
}
dfs(0,-1,H,a);
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
vector<int> dist(N+1,1e9);
// dist[N]=0;
// q.push({0,N});
// for (int i: nodes) {
// al[N].push_back({i,0});
// al[i].push_back({N,0});
// }
dist[0]=0;
q.push({0,0});
while (!q.empty()) {
int u=q.top().second; q.pop();
for (auto v: al[u]) {
if (dist[u]+v.second<dist[v.first]) {
dist[v.first]=dist[u]+v.second;
q.push({dist[v.first],v.first});
}
}
}
if (dist[H]==1e9) return -1;
return (double)dist[H];
}
# | 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... |