제출 #975644

#제출 시각아이디문제언어결과실행 시간메모리
975644XXBabaProBerkay사이버랜드 (APIO23_cyberland)C++17
0 / 100
1556 ms2097264 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; #define F first #define S second const double INF = 1e18 + 7; vector<vector<pair<int, double>>> adj; vector<bool> vis; void DFS(int k, int& H) { if (vis[k] || k == H) return; vis[k] = 1; for (pair<int, double> i : adj[k]) DFS(i.F, H); } double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { adj.resize(N); for (int i = 0; i < M; i++) { adj[x[i]].emplace_back(y[i], c[i]); adj[y[i]].emplace_back(x[i], c[i]); } vis.resize(N); DFS(0, H); priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> PQ; vector<vector<double>> dist(N, vector<double>(K + 1, INF)); for (int i = 0; i < N; i++) if (vis[i] && arr[i] == 0) { dist[i][0] = 0; PQ.emplace(0, i); } dist[0][0] = 0; PQ.emplace(0, 0); while (!PQ.empty()) { double d; int u; tie(d, u) = PQ.top(); PQ.pop(); if (d != dist[u][0] || u == H) continue; for (pair<int, double> i : adj[u]) { int v; double w; tie(v, w) = i; if (dist[v][0] > dist[u][0] + w) PQ.emplace(dist[v][0] = dist[u][0] + w, v); } } for (int i = 1; i <= K; i++) { for (int j = 0; j < N; j++) if (vis[j] && arr[j] == 0) { dist[j][i] = 0; PQ.emplace(0, j); } dist[0][i] = 0; PQ.emplace(0, 0); while (!PQ.empty()) { int u; double d; tie(d, u) = PQ.top(); PQ.pop(); if (d != dist[u][i] || u == H) continue; for (pair<int, double> j : adj[u]) { int v; double w; tie(v, w) = j; if (dist[v][i] > (dist[u][i - 1] + w) / 2.0 && arr[v] == 2) PQ.emplace(dist[v][i] = (dist[u][i - 1] + w) / 2.0, v); if (dist[v][i] > dist[u][i] + w) PQ.emplace(dist[v][i] = dist[u][i] + w, v); } } } return (dist[H][K] == INF ? -1 : dist[H][K]); }
#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...