Submission #970602

# Submission time Handle Problem Language Result Execution time Memory
970602 2024-04-26T18:25:59 Z SuPythony Cyberland (APIO23_cyberland) C++17
8 / 100
1436 ms 2097152 KB
#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
1 Incorrect 15 ms 816 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1120 KB Correct.
2 Correct 31 ms 1528 KB Correct.
3 Correct 21 ms 1916 KB Correct.
4 Correct 23 ms 1536 KB Correct.
5 Correct 23 ms 1628 KB Correct.
6 Correct 68 ms 3152 KB Correct.
7 Correct 73 ms 3216 KB Correct.
8 Correct 237 ms 4684 KB Correct.
9 Correct 20 ms 1372 KB Correct.
10 Correct 19 ms 1372 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 1372 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1436 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 787 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 815 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 831 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 834 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -