Submission #779892

# Submission time Handle Problem Language Result Execution time Memory
779892 2023-07-12T02:07:45 Z vjudge1 Sirni (COCI17_sirni) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e5;
const int maxM = 1e5;
int n, m, k;
struct TEdge 
{
    int u, v;      
    int w;         
    bool selected; 
};
using PEdge = TEdge*; 
TEdge e[maxM]; 
PEdge p[maxM]; 
int lab[maxN]; 
void ReadInput(
 {
     cin >> n >> m;
     for (int i = 0; i < m; ++i)
    {
        cin >> e[i].u >> e[i].v >> e[i].w;
        e[i].selected = false; 
        p[i] = &e[i]; 
    }
}

 void Init()
{
     sort(p, p + m, [](PEdge e1, PEdge e2) 
    {
         return e1->w < e2->w; 
     });
    fill(lab, lab + n, -1); 
}

int FindSet(int u) 
{
   return lab[u] < 0 ? u : lab[u] = FindSet(lab[u]);
}

 void Unite(int r, int s)
{
    if (lab[r] > lab[s]) 
         swap(r, s);      
    lab[r] += lab[s]; 
    lab[s] = r; 
}

 void Kruskal()
{
   k = 0; 
   for (int i = 0; i < m; ++i)
   { 
      int r = FindSet(p[i]->u), s = FindSet(p[i]->v);
        if (r != s) 
        {
           p[i]->selected = true; 
            Unite(r, s);           
            ++k;                   
           if (k == n - 1) 
               break;      
      }
   }
}
void Print() 
 {
    if (k < n - 1) 
        cout << "DISCONNECTED"; 
    else 
    {
       int TreeWeight = 0;
       for (int i = 0; i < m; ++i)
           if (e[i].selected) 
             {
               TreeWeight += e[i].w;
             }
        cout << TreeWeight << '\n';
    }
}
 int main()
{
    ReadInput();
    Init();
    Kruskal();
    Print();
}

Compilation message

sirni.cpp:16:6: error: variable or field 'ReadInput' declared void
   16 | void ReadInput(
      |      ^~~~~~~~~
sirni.cpp:18:19: error: expected '}' before ';' token
   18 |      cin >> n >> m;
      |                   ^
sirni.cpp:17:2: note: to match this '{'
   17 |  {
      |  ^
sirni.cpp:18:19: error: expected ')' before ';' token
   18 |      cin >> n >> m;
      |                   ^
      |                   )
sirni.cpp:16:15: note: to match this '('
   16 | void ReadInput(
      |               ^
sirni.cpp:19:6: error: expected unqualified-id before 'for'
   19 |      for (int i = 0; i < m; ++i)
      |      ^~~
sirni.cpp:19:22: error: 'i' does not name a type
   19 |      for (int i = 0; i < m; ++i)
      |                      ^
sirni.cpp:19:29: error: expected unqualified-id before '++' token
   19 |      for (int i = 0; i < m; ++i)
      |                             ^~
sirni.cpp:25:1: error: expected declaration before '}' token
   25 | }
      | ^
sirni.cpp: In function 'int main()':
sirni.cpp:82:5: error: 'ReadInput' was not declared in this scope
   82 |     ReadInput();
      |     ^~~~~~~~~