Submission #876785

# Submission time Handle Problem Language Result Execution time Memory
876785 2023-11-22T10:29:31 Z dimashhh Cyberland (APIO23_cyberland) C++17
49 / 100
1705 ms 52816 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 1e5;

double d[N][70];
double solve(int n, int m, int k, int h, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr)
{
    vector<pair<int, double>> g[N];   
    if(k >= 66){
        k = 66;
    }
    for (int i = 0; i < n; i++)
    {
        for(int j = 0;j <= k;j++){
            d[i][j] = 1e15;
        }
        g[i].clear();
    }
    for (int i = 0; i < m; i++)
    {
        g[x[i]].push_back({y[i], c[i]});
        g[y[i]].push_back({x[i], c[i]});
    }
    queue<int> q;
    vector<int> can(n,0);
    can[0] = 1;
    q.push(0);
    priority_queue<pair<double,pair<int,int>>> st;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        if(!can[v]) continue;
        if((arr[v] == 0 || v == 0) && can[v]){
            d[v][0] = 0;
            st.push({0,{0,v}});
        }
        for(auto [to,w]:g[v]){
            if(to == h || can[to]) continue;
            q.push(to);
            can[to] = 1;
        }
    }
    
    st.push({0,{0,0}});
    double res = 1e15;
    while(!st.empty()){
        auto [col,v] = (st.top()).second;
        st.pop();
        if(d[v][col] == -1) continue;
        if(v == h){
            res = min(res,d[v][col]);
            continue;
        }
        for(auto [to,w]:g[v]){
            if(d[to][col + 1] != -1 && col + 1 <= k && arr[to] == 2 && d[to][col + 1] > (d[v][col] + w) / 2){
                d[to][col + 1] = (d[v][col] + w) / 2;
                st.push({-d[to][col + 1],{col + 1,to}});
            }
            if(d[to][col] != -1 && d[to][col] > d[v][col] + w){
                d[to][col] = d[v][col] + w;
                st.push({-d[to][col],{col,to}});
            }
        }
        d[v][col] = -1;
    }
    if(res == 1e15) res = -1;
    return res;
}
// int main() {
//   int T;
//   assert(1 == scanf("%d", &T));
//   while (T--){
//     int N,M,K,H;
//     assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H));
//     std::vector<int> x(M);
//     std::vector<int> y(M);
//     std::vector<int> c(M);
//     std::vector<int> arr(N);
//     for (int i=0;i<N;i++)
//       assert(1 == scanf("%d", &arr[i]));
//     for (int i=0;i<M;i++)
//       assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i]));
//     printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr));
//   }
// }
# Verdict Execution time Memory Grader output
1 Correct 1705 ms 3156 KB Correct.
2 Correct 1696 ms 3128 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 43 ms 4956 KB Correct.
2 Correct 42 ms 5156 KB Correct.
3 Correct 41 ms 4956 KB Correct.
4 Correct 43 ms 4956 KB Correct.
5 Correct 46 ms 4956 KB Correct.
6 Correct 23 ms 9820 KB Correct.
7 Correct 30 ms 9816 KB Correct.
8 Correct 13 ms 16984 KB Correct.
9 Correct 199 ms 2888 KB Correct.
10 Correct 187 ms 2648 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 45 ms 4956 KB Correct.
2 Correct 45 ms 4956 KB Correct.
3 Correct 52 ms 5220 KB Correct.
4 Correct 191 ms 2892 KB Correct.
5 Correct 190 ms 2888 KB Correct.
6 Correct 7 ms 9820 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 115 ms 42700 KB Correct.
2 Incorrect 147 ms 5336 KB Wrong Answer.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 4952 KB Correct.
2 Correct 50 ms 5124 KB Correct.
3 Correct 44 ms 4956 KB Correct.
4 Correct 24 ms 9820 KB Correct.
5 Correct 191 ms 2876 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 49 ms 5152 KB Correct.
2 Correct 43 ms 5188 KB Correct.
3 Correct 38 ms 52816 KB Correct.
4 Correct 18 ms 7772 KB Correct.
5 Correct 193 ms 2652 KB Correct.
6 Correct 48 ms 4956 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 179 ms 5528 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 348 ms 6100 KB Wrong Answer.
2 Halted 0 ms 0 KB -