From 2138f78464118cf841e135694f382b7dd22b29da Mon Sep 17 00:00:00 2001 From: Liza Gorbach <55574567+Liza04@users.noreply.github.com> Date: Thu, 2 May 2024 09:59:56 +0700 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=20=D0=B1=D1=8B=D0=BB=D0=BE=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=BE,=20=D1=87?= =?UTF-8?q?=D1=82=D0=BE=20=D0=BD=D1=83=D0=B6=D0=BD=D0=BE=20=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=82=D1=8C=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=88=D0=B8=D0=BD=D1=8B=20(=D0=B1=D0=B5=D0=B7=20?= =?UTF-8?q?=D1=8D=D1=82=D0=BE=D0=B3=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B5=20=D0=B1=D1=83=D0=B4=D0=B5?= =?UTF-8?q?=D1=82)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/russian/cs/spanning-trees/prim.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/content/russian/cs/spanning-trees/prim.md b/content/russian/cs/spanning-trees/prim.md index ff250c70..b42edf64 100644 --- a/content/russian/cs/spanning-trees/prim.md +++ b/content/russian/cs/spanning-trees/prim.md @@ -71,14 +71,16 @@ for (int i = 0; i < n; i++) { ```c++ set< pair > q; int d[maxn]; +int used[maxn]; while (q.size()) { v = q.begin()->second; q.erase(q.begin()); - + used[v] = 1; + for (auto e : g[v]) { int u = e.first, w = e.second; - if (w < d[u]) { + if (w < d[u] && !used[u]) { q.erase({d[u], u}); d[u] = w; q.insert({d[u], u});