제출 #984973

#제출 시각아이디문제언어결과실행 시간메모리
984973javotaz사이버랜드 (APIO23_cyberland)C++17
44 / 100
92 ms25808 KiB
// In the Name of Allah #include<bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,unroll-loops,fast-math") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") typedef long long ll; typedef pair<double, int> pd; #define F first #define S second #define pii pair<int, int> #define pb push_back #define pp pop_back #define all(x) x.begin(), x.end() const int N = 1e5 + 12, K = 77; vector<pii> g[N]; int n, m, k, h, a[N]; double ans; bool mrk[N][K], t[N]; void dfs(int u) { t[u] = true; if (u == h) return; for (auto i: g[u]) if (!t[i.F]) dfs(i.F); } void find_ans() { dfs(0); ans = 1e18; if (!t[h]) { ans = -1; return; } priority_queue<pd, vector<pd>, greater<pd>> q[k + 1]; q[0].push({0, 0}); for (int i = 1; i < n; i++) if (!a[i] && t[i]) q[0].push({0, i}); int pt = 0; while (pt <= k) { if (q[pt].empty()) { ++pt; continue; } auto [w, u] = q[pt].top(); q[pt].pop(); if (u == h) { ans = min(ans, w); mrk[u][pt] = true; } if (mrk[u][pt]) continue; mrk[u][pt] = true; for (auto i: g[u]) if (a[i.F]) { if (!mrk[i.F][pt]) q[pt].push({w + i.S, i.F}); if (a[i.F] == 2) q[pt + 1].push({(w + i.S) / 2, i.F}); } } } double solve(int ns, int ms, int ks, int hs, vector<int> xs, vector<int> ys, vector<int> ws, vector<int> as) { n = ns, m = ms, k = min(ks, 75), h = hs; for (int i = 0; i < m; i++) g[xs[i]].pb({ys[i], ws[i]}), g[ys[i]].pb({xs[i], ws[i]}); for (int i = 0; i < n; i++) a[i] = as[i]; find_ans(); for (int i = 0; i < n; i++) { g[i].clear(); t[i] = false; for (int j = 0; j <= k; ++j) mrk[i][j] = false; } 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...