Language: C++

#include<bits/stdc++.h>
struct Unionfind{
  vector<int> d;
  vector<int> r;
  Unionfind(int n){
    d.resize(n,-1);
    r.resize(n,-1);
  }
  int find(int x){
     if(d[x]<0) return;
     else d[x]=find(d[x]);
  }
  int unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(r[x]>r[y]) swap(x,y);
    if(r[x]==r[y]){
       r[y]++;
    }
    p[x]=y;
  }
};

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(m),b(m);
  for(int i=0;i<m;i++)
  {
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
  }
  int bridge=0;
  for(int j=0;j<m;j++){
    Unionfind uf(n);
    bool ok=true;
    for(int i=0;i<m;i++){
      if(i!=j) tree.unite(a[i],b[i]);
    }
    for(int i=0;i<n;i++){
        if(tree.find(i)!=tree.root(i+1)) ok=false;
    }
    if(!ok) bridge++;
  }
    cout<<bridge<<endl;
    return 0;
}
  


Compiler output:
a.cc:3:3: error: 'vector' does not name a type
    3 |   vector<int> d;
      |   ^~~~~~
a.cc:4:3: error: 'vector' does not name a type
    4 |   vector<int> r;
      |   ^~~~~~
a.cc: In constructor 'Unionfind::Unionfind(int)':
a.cc:6:5: error: 'd' was not declared in this scope
    6 |     d.resize(n,-1);
      |     ^
a.cc:7:5: error: 'r' was not declared in this scope
    7 |     r.resize(n,-1);
      |     ^
a.cc: In member function 'int Unionfind::find(int)':
a.cc:10:9: error: 'd' was not declared in this scope
   10 |      if(d[x]<0) return;
      |         ^
a.cc:10:17: error: return-statement with no value, in function returning 'int' [-fpermissive]
   10 |      if(d[x]<0) return;
      |                 ^~~~~~
a.cc: In member function 'int Unionfind::unite(int, int)':
a.cc:16:14: error: return-statement with no value, in function returning 'int' [-fpermissive]
   16 |     if(x==y) return;
      |              ^~~~~~
a.cc:17:8: error: 'r' was not declared in this scope
   17 |     if(r[x]>r[y]) swap(x,y);
      |        ^
a.cc:17:19: error: 'swap' was not declared in this scope
   17 |     if(r[x]>r[y]) swap(x,y);
      |                   ^~~~
a.cc:17:19: note: suggested alternatives:
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181,
                 from a.cc:1:
/usr/include/c++/14/bits/regex.h:2230:5: note:   'std::__cxx11::swap'
 2230 |     swap(match_results<_Bi_iter, _Alloc>& __lhs,
      |     ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:61,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/move.h:226:5: note:   'std::swap'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   'std::swap'
In file included from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/stdexcept:38,
                 from /usr/include/c++/14/system_error:43,
                 from /usr/include/c++/14/bits/ios_base.h:46,
                 from /usr/include/c++/14/streambuf:43,
                 from /usr/include/c++/14/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/exception_ptr.h:229:5: note:   'std::__exception_ptr::swap'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
In file included from /usr/include/c++/14/filesystem:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:200:
/usr/include/c++/14/bits/fs_path.h:736:15: note:   'std::filesystem::__cxx11::swap'
  736 |   inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
      |               ^~~~
a.cc:18:8: error: 'r' was not declared in this scope
   18 |     if(r[x]==r[y]){
      |        ^
a.cc:21:5: error: 'p' was not declared in this scope
   21 |     p[x]=y;
      |     ^
a.cc: In function 'int main()':
a.cc:27:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   27 |   cin>>n>>m;
      |   ^~~
      |   std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:28:3: error: 'vector' was not declared in this scope
   28 |   vector<int> a(m),b(m);
      |   ^~~~~~
a.cc:28:3: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:28:10: error: expected primary-expression before 'int'
   28 |   vector<int> a(m),b(m);
      |          ^~~
a.cc:31:10: error: 'a' was not declared in this scope
   31 |     cin>>a[i]>>b[i];
      |          ^
a.cc:31:16: error: 'b' was not declared in this scope
   31 |     cin>>a[i]>>b[i];
      |                ^
a.cc:40:16: error: 'tree' was not declared in this scope; did you mean 'free'?
   40 |       if(i!=j) tree.unite(a[i],b[i]);
      |                ^~~~
      |                free
a.cc:40:27: error: 'a' was not declared in this scope
   40 |       if(i!=j) tree.unite(a[i],b[i]);
      |                           ^
a.cc:40:32: error: 'b' was not declared in this scope
   40 |       if(i!=j) tree.unite(a[i],b[i]);
      |                                ^
a.cc:43:12: error: 'tree' was not declared in this scope; did you mean 'free'?
   43 |         if(tree.find(i)!=tree.root(i+1)) ok=false;
      |            ^~~~
      |            free
a.cc:47:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   47 |     cout<<bridge<<endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:47:19: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   47 |     cout<<bridge<<endl;
      |                   ^~~~
      |                   std::endl
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~