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 <bits/stdc++.h>
using namespace std;
vector<pair<int,int> > G[100005];
double rez=0;
int N, megju[100005], vizz[100005];
vector<int> arr1;
bool dfs(int teme, int kraj) {
if (teme==kraj) {
megju[teme]=1;
return true;
}
vizz[teme]=1;
bool ok=false;
for (auto next:G[teme])
if (vizz[next.first]==0)
if (dfs(next.first, kraj))
ok=true;
return megju[teme]=ok;
}
void dijkstra(int poc) {
bool vis[N]={0};
double dist[N];
for (int i=0;i<N;i++)
dist[i]=1e15;
priority_queue<pair<double,int> > pq;
pq.push({0,poc});
dist[poc]=0;
int t=-1;
while (!pq.empty()) {
int teme=pq.top().second;
pq.pop();
if (vis[teme]) continue;
vis[teme]=1;
if ((arr1[teme]==0||teme==0)&&megju[teme]==1) {
t=teme;
break;
}
for (auto x:G[teme]) {
int next=x.first, dist_between=x.second;
if (dist[next]>dist[teme]+dist_between) {
dist[next]=dist[teme]+dist_between;
pq.push({-dist[next], next});
}
}
}
if (t==-1) rez=-1;
else rez=dist[t];
}
double solve(int n, int m, int k, int h, vector<int> a, vector<int> b, vector<int> c, vector<int> arr) {
for (int i=0;i<n;i++)
G[i].clear(), megju[i]=0, vizz[i]=0;
N=n;
arr1=arr;
for (int i=0;i<m;i++) {
G[a[i]].push_back({b[i],c[i]});
G[b[i]].push_back({a[i],c[i]});
}
dfs(0,h);
dijkstra(h);
return rez;
}
Compilation message (stderr)
cyberland.cpp: In function 'bool dfs(int, int)':
cyberland.cpp:21:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
21 | return megju[teme]=ok;
| ~~~~~~~~~~~^~~
# | 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... |