Language: C++

#include <bits/stdc++.h>
#define int long long
#define N 1000
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}

#define rank Asdfiasofsad
class UF{
public:
  int V;
  vector<int> par,rank;
  UF(){}
  UF(int V):V(V),par(V),rank(V,0){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y])par[x]=y;
    else{
      par[y]=x;
      if(rank[x]==rank[y])rank[x]++;
    }
  }

  bool same(int x,int y){return find(x)==find(y);}
};

int n,m;
vector<int> G[N];

int used[N];
int dfs(int pos){
  if(used[pos]++) return 0;
  int res = G[pos].size() - 1;
  for(int to:G[pos]) res += dfs(to);
  return res;
}

signed main(){
  cin>>n>>m;
  UF uf(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b; a--,b--;
    G[a].push_back(b);
    uf.unite(a,b);
  }
  
  map<int,int> val;
  for(int i=0;i<n;i++){
    memset(used,0,sizeof(used));
    int v = dfs(i);
    if(val.count(uf.find(i))) Min(val[uf.find(i)],v);
    else val[uf.find(i)] = v;
  }

  int sum = 0;
  typedef pair<int,int> P;
  for(P p:val) sum += p.second+1;
  cout<<sum<<endl;
  
  return 0;
}
#include <bits/stdc++.h>
#define int long long
#define N 1000
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}

#define rank Asdfiasofsad
class UF{
public:
  int V;
  vector<int> par,rank;
  UF(){}
  UF(int V):V(V),par(V),rank(V,0){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y])par[x]=y;
    else{
      par[y]=x;
      if(rank[x]==rank[y])rank[x]++;
    }
  }

  bool same(int x,int y){return find(x)==find(y);}
};

int n,m;
vector<int> G[N];

int used[N];
int dfs(int pos){
  if(used[pos]++) return 0;
  int res = G[pos].size() - 1;
  for(int to:G[pos]) res += dfs(to);
  return res;
}

signed main(){
  cin>>n>>m;
  UF uf(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b; a--,b--;
    G[a].push_back(b);
    uf.unite(a,b);
  }
  
  map<int,int> val;
  for(int i=0;i<n;i++){
    memset(used,0,sizeof(used));
    int v = dfs(i);
    if(val.count(uf.find(i))) Min(val[uf.find(i)],v);
    else val[uf.find(i)] = v;
  }

  int sum = 0;
  typedef pair<int,int> P;
  for(P p:val) sum += p.second+1;
  cout<<sum<<endl;
  
  return 0;
}

Compiler output:
a.cc:79:11: error: redefinition of 'const long long int INF'
   79 | const int INF = 1LL<<55;
      |           ^~~
a.cc:5:11: note: 'const long long int INF' previously defined here
    5 | const int INF = 1LL<<55;
      |           ^~~
a.cc:80:11: error: redefinition of 'const long long int mod'
   80 | const int mod = (1e9)+7;
      |           ^~~
a.cc:6:11: note: 'const long long int mod' previously defined here
    6 | const int mod = (1e9)+7;
      |           ^~~
a.cc:81:14: error: redefinition of 'const double EPS'
   81 | const double EPS = 1e-8;
      |              ^~~
a.cc:7:14: note: 'const double EPS' previously defined here
    7 | const double EPS = 1e-8;
      |              ^~~
a.cc:82:14: error: redefinition of 'const double PI'
   82 | const double PI = 6.0 * asin(0.5);
      |              ^~
a.cc:8:14: note: 'const double PI' previously defined here
    8 | const double PI = 6.0 * asin(0.5);
      |              ^~
a.cc:83:21: error: redefinition of 'template<class T> T Max(T&, T)'
   83 | template<class T> T Max(T &a,T b){return a=max(a,b);}
      |                     ^~~
a.cc:9:21: note: 'template<class T> T Max(T&, T)' previously declared here
    9 | template<class T> T Max(T &a,T b){return a=max(a,b);}
      |                     ^~~
a.cc:84:21: error: redefinition of 'template<class T> T Min(T&, T)'
   84 | template<class T> T Min(T &a,T b){return a=min(a,b);}
      |                     ^~~
a.cc:10:21: note: 'template<class T> T Min(T&, T)' previously declared here
   10 | template<class T> T Min(T &a,T b){return a=min(a,b);}
      |                     ^~~
a.cc:87:7: error: redefinition of 'class UF'
   87 | class UF{
      |       ^~
a.cc:13:7: note: previous definition of 'class UF'
   13 | class UF{
      |       ^~
a.cc:113:5: error: redefinition of 'long long int n'
  113 | int n,m;
      |     ^
a.cc:39:5: note: 'long long int n' previously declared here
   39 | int n,m;
      |     ^
a.cc:113:7: error: redefinition of 'long long int m'
  113 | int n,m;
      |       ^
a.cc:39:7: note: 'long long int m' previously declared here
   39 | int n,m;
      |       ^
a.cc:114:13: error: redefinition of 'std::vector<long long int> G [1000]'
  114 | vector<int> G[N];
      |             ^
a.cc:40:13: note: 'std::vector<long long int> G [1000]' previously declared here
   40 | vector<int> G[N];
      |             ^
a.cc:116:5: error: redefinition of 'long long int used [1000]'
  116 | int used[N];
      |     ^~~~
a.cc:42:5: note: 'long long int used [1000]' previously declared here
   42 | int used[N];
      |     ^~~~
a.cc:117:5: error: redefinition of 'long long int dfs(long long int)'
  117 | int dfs(int pos){
      |     ^~~
a.cc:43:5: note: 'long long int dfs(long long int)' previously defined here
   43 | int dfs(int pos){
      |     ^~~
a.cc:124:8: error: redefinition of 'int main()'
  124 | signed main(){
      |        ^~~~
a.cc:50:8: note: 'int main()' previously defined here
   50 | signed main(){
      |        ^~~~