이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<pair<int,double>>> al;
vector<int> on_path;
double ans;
bool found;
void find_path(int i, int p, vector<int> path, int f) {
path.push_back(i);
if (i==f) {
found=true;
for (int v: path) on_path[v]=1;
return;
}
for (auto v: al[i]) {
if (v.first==p) continue;
find_path(v.first,i,path,f);
if (found) return;
}
path.pop_back();
}
double dfs(int i, int p, double c, int f, vector<int> a) {
if (i==f) {
ans=c;
return c;
}
double curr=c;
if (a[i]==0) c=0;
int next=-1;
double next_s;
for (auto v: al[i]) {
if (v.first==p) continue;
if (on_path[v.first]) {
next=v.first;
next_s=v.second;
}
else {
double t=dfs(v.first,i,c+v.second,f,a);
curr=min(curr,t);
}
}
if (next!=-1) {
dfs(next,i,curr+next_s,f,a);
}
return curr;
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int>
y, vector<int> c, vector<int> a) {
ans=1e9;
found=false;
on_path.assign(N,0);
al.assign(N,vector<pair<int,double>>());
for (int i=0; i<M; i++) {
al[x[i]].push_back({y[i],(double)c[i]});
al[y[i]].push_back({x[i],(double)c[i]});
}
find_path(0,-1,vector<int>(),H);
dfs(0,-1,0,H,a);
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... |