제출 #970602

#제출 시각아이디문제언어결과실행 시간메모리
970602SuPythonyCyberland (APIO23_cyberland)C++17
8 / 100
1436 ms2097152 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...