Submission #749886

#TimeUsernameProblemLanguageResultExecution timeMemory
7498861neCyberland (APIO23_cyberland)C++17
13 / 100
955 ms30896 KiB
#include "cyberland.h" #include <bits/stdc++.h> #include <vector> using namespace std; struct node{ int x,y; double v; bool operator < (const node& P)const{ return P.v < v; } }; 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<vector<pair<int,int>>>adj(N); for (int i = 0;i<M;++i){ adj[x[i]].push_back({y[i],c[i]}); adj[y[i]].push_back({x[i],c[i]}); } K = min(100,K); priority_queue<node>q; q.push({0,K,0}); vector<vector<double>>dist(N,vector<double>(K + 1,1e12)); vector<vector<int>>visited(N,vector<int>(K + 1,0)); dist[0][K] = 0; visited[0][K] = 1; while(!q.empty()){ auto u = q.top(); q.pop(); visited[u.x][u.y] = 0; if (u.x == H)continue; if (u.v != dist[u.x][u.y])continue; for (auto x:adj[u.x]){ long long v = x.second; if (arr[x.first] == 0){ v = -dist[u.x][u.y]; } if (dist[x.first][u.y] > dist[u.x][u.y] + v){ dist[x.first][u.y] = dist[u.x][u.y] + v; if (!visited[x.first][u.y]){ q.push({x.first,u.y,dist[x.first][u.y]}); visited[x.first][u.y] = 1; } } if (arr[x.first] == 2 && u.y > 0){ if (dist[x.first][u.y - 1] > (dist[u.x][u.y] + x.second)/2){ dist[x.first][u.y - 1] = (dist[u.x][u.y] + x.second)/2; if (!visited[x.first][u.y - 1]){ q.push({x.first,u.y - 1,dist[x.first][u.y - 1]}); visited[x.first][u.y - 1] = 1; } } //nx = dist[u.first][u.second] + x.second)/2 + 2 * vx) / 2 + 2 * vx ) / 2 } } } double ans = 1e12; for (int i = 0;i<=K;++i){ ans = min(ans,dist[H][i]); } if (ans == 1e12)return -1; 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...