title: Prim Algorithm application
body: <p>everyone, I have a weighted connected undirected graph, I need to find it's minimum spanning tree weight. On input I have numbers n(vertices amount), m(edges amount). And then m edges in format: A(out vert), B(in vert), C(weight). Here is input example:</p>
  <pre><code>3 3
  1 2 1
  2 3 2
  3 1 3
  </code></pre>
  <p>I see it as a typical Prim algorithm, so I used it, but some tests are telling me that my code gives a wrong answer. Here it is:</p>
  <pre><code>#include &lt;numeric&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  long long primAlgo(const int vertices, const vector&lt;vector&lt;long long&gt;&gt; &amp;edges) {
      vector&lt;bool&gt; visited(vertices, false);
      vector&lt;long long&gt; minimal(vertices, 30001);
  
      minimal[0] = 0;
      for (size_t i = 0; i != vertices; ++i) {
          int vert = -1;
          for (size_t option = 0; option != vertices; ++option) {
              if (!visited[option] &amp;&amp; (vert == -1 || minimal[option] &lt; minimal[vert]))
                  vert = option;
          }
          visited[vert] = true;
  
          for (size_t to = 0; to != vertices; ++to) {
              if (edges[vert][to] &lt; minimal[to]) {
                 minimal[to] = edges[vert][to];
              }
          }
      }
  
      long long sum = 0;
  
      for (size_t i = 0; i != vertices; ++i) {
          sum += minimal[i];
      }
      return sum;
  }
  
  int main() {
      int n, m;
      cin &gt;&gt; n &gt;&gt; m;
      int A, B;
      long long C;
      vector&lt;vector&lt;long long&gt;&gt; l(n, vector&lt;long long&gt; (n, 30001));
      for (size_t i = 0; i != m; ++i) {
          cin &gt;&gt; A &gt;&gt; B &gt;&gt; C;
          l[A - 1][B - 1] = C;
          l[B - 1][A - 1] = C;
      }
  
      long long ans = primAlgo(n, l);
      cout &lt;&lt; ans;
  }
  
  </code></pre>
  <p>So I was wondering, if you know, what the problem may be.</p>