From 64b9d01b4da4aa30b156ddad7954b60a6f435021 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 30 Sep 2025 22:05:39 +0900 Subject: [PATCH] =?UTF-8?q?[20250930]=20BOJ=20/=20P3=20/=20Alternative=20M?= =?UTF-8?q?art=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- khj20006/202509/30 BOJ P3 Alternative Mart.md | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 khj20006/202509/30 BOJ P3 Alternative Mart.md diff --git a/khj20006/202509/30 BOJ P3 Alternative Mart.md b/khj20006/202509/30 BOJ P3 Alternative Mart.md new file mode 100644 index 00000000..8749b3e7 --- /dev/null +++ b/khj20006/202509/30 BOJ P3 Alternative Mart.md @@ -0,0 +1,83 @@ +```cpp +#include +using namespace std; + +int N, M, K, Q; +vector>> V(50001); +vector>> D(50001); +priority_queue, vector>, greater<>> PQ; + +int main() { + cin.tie(0)->sync_with_stdio(0); + + for (cin >> N >> M >> K >> Q; K--;) { + int a; + cin >> a; + PQ.emplace(0, a, a); + D[a].emplace_back(0, a); + } + for (int a, b, c; M--; V[a].emplace_back(b, c), V[b].emplace_back(a, c)) cin >> a >> b >> c; + + while (!PQ.empty()) { + auto [d, p, n] = PQ.top(); PQ.pop(); + bool con = false, ex = false; + for (auto [_, q] : D[n]) { + if (q == p) { + ex = 1; + if (d > _) con = 1; + } + } + if (!ex) con = 1; + if (con) continue; + for (auto [i, c] : V[n]) { + int org = -1; + for (auto [_, q] : D[i]) { + if (p == q) org = _; + } + stack> tmp; + if (org == -1) { + while (!D[i].empty() && D[i].back().first > d+c) { + tmp.push(D[i].back()); + D[i].pop_back(); + } + if (D[i].size() < 11) { + D[i].emplace_back(d + c, p); + PQ.emplace(d + c, p, i); + } + while (D[i].size() < 11 && !tmp.empty()) { + D[i].emplace_back(tmp.top()); + tmp.pop(); + } + } + else if (d + c < org) { + while (!D[i].empty() && D[i].back().first > d+c) { + if(D[i].back().second != p) tmp.push(D[i].back()); + D[i].pop_back(); + } + D[i].emplace_back(d + c, p); + while (!tmp.empty()) { + D[i].emplace_back(tmp.top()); + tmp.pop(); + } + PQ.emplace(d + c, p, i); + } + } + } + + for (int s, c, a; Q--;) { + vector t; + for (cin >> s >> c; c--; t.push_back(a)) cin >> a; + bool pr = false; + for (int i = 0; i < D[s].size(); i++) { + bool cant = false; + for (int j : t) cant |= j == D[s][i].second; + if (!cant) { + pr = true; + cout << D[s][i].second << ' ' << D[s][i].first << '\n'; + break; + } + } + } + +} +```