Language: C++

#include<bits/stdc++.h>
#define N 100
using namespace std;
typedef pair<int,int> P;

int n,m,k,a,b,c,cntg,mark,f,num,p,cnt,cnt2,ans;
vector<P> e[N],v;
int used[N];
bool usede[N][N],close[N][N];

void func(int x){
  used[x]=mark;
  for(int i=0;i<(int)e[x].size();i++)
    if(!used[e[x][i].first])func(e[x][i].first);
}

bool func2(int x){
  used[x]=1;
  for(int i=0;i<(int)e[x].size();i++){
    int nx=e[x][i].first;
    if(usede[x][nx])continue;
    usede[x][nx]=usede[nx][x]=true;
    if(used[nx]){
      p=e[x][i].first;
      close[x][nx]=true;
      close[nx][x]=true;
      return true;
    }
    else if(func2(nx)){
      close[x][nx]=true;
      close[nx][x]=true;
    }
  }
  return false;
}

int main(){
  cin>>n>>m>>k;
  for(int i=0;i<m;i++){
    cin>>a>>b>>c;
    e[a-1].push_back(P(b-1,c));
    e[b-1].push_back(P(a-1,c));
  }
  num=1;
  for(int i=0;i<n;i++)
    if(!used[i]){
      mark=num;
      cntg++;
      func(i);
      num++;
    }
  for(int i=1;i<cntg;i++){
    f=0;
    for(int j=0;j<n;j++){
      if(used[j]!=i)continue;
      for(int k=0;k<n;k++)
	if(used[k]==i+1){
	  f=1;
	  e[j].push_back(P(k,0));
	  break;
	}
      if(f)break;
    }
  }
  memset(used,0,sizeof(used));
  memset(usede,0,sizeof(usede));
  func2(0);
  for(int i=0;i<n;i++){
    for(int j=0;j<(int)e[i].size();j++){
      int ni=e[i][j].first,cost=e[i][j].second;
      if(i<ni){
	if(!close[i][ni])v.push_back(P(0,cost)),cnt++;
	else v.push_back(P(1,cost)),cnt2++;
      }
    }
  }
  sort(v.begin(),v.end());
  ans=(1e9);
  int sum=0;
  if(cnt>=k-1){
    for(int i=0;i<k-1;i++)sum+=v[i].second;
    ans=sum;
  }
  if(cnt2){
    for(int i=cnt+1;i<(int)v.size();i++){
      sum=v[i].second;
      for(int j=0,l=0;j<(int)v.size();j++){
	if(i==j)continue;
	l++;
	sum+=v[j].second;
	if(l==k-1)break;
      }
      ans=min(ans,sum);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Compiler output:
a.cc:9:28: error: 'bool close [100][100]' redeclared as different kind of entity
    9 | bool usede[N][N],close[N][N];
      |                            ^
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:1:
/usr/include/unistd.h:358:12: note: previous declaration 'int close(int)'
  358 | extern int close (int __fd);
      |            ^~~~~
a.cc: In function 'bool func2(int)':
a.cc:25:14: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   25 |       close[x][nx]=true;
      |              ^
a.cc:25:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   25 |       close[x][nx]=true;
      |                  ^
a.cc:25:19: error: assignment of read-only location '*(close + (((sizetype)x) + ((sizetype)nx)))'
   25 |       close[x][nx]=true;
      |       ~~~~~~~~~~~~^~~~~
a.cc:26:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   26 |       close[nx][x]=true;
      |               ^
a.cc:26:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   26 |       close[nx][x]=true;
      |                  ^
a.cc:26:19: error: assignment of read-only location '*(close + (((sizetype)nx) + ((sizetype)x)))'
   26 |       close[nx][x]=true;
      |       ~~~~~~~~~~~~^~~~~
a.cc:30:14: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   30 |       close[x][nx]=true;
      |              ^
a.cc:30:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   30 |       close[x][nx]=true;
      |                  ^
a.cc:30:19: error: assignment of read-only location '*(close + (((sizetype)x) + ((sizetype)nx)))'
   30 |       close[x][nx]=true;
      |       ~~~~~~~~~~~~^~~~~
a.cc:31:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   31 |       close[nx][x]=true;
      |               ^
a.cc:31:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   31 |       close[nx][x]=true;
      |                  ^
a.cc:31:19: error: assignment of read-only location '*(close + (((sizetype)nx) + ((sizetype)x)))'
   31 |       close[nx][x]=true;
      |       ~~~~~~~~~~~~^~~~~
a.cc: In function 'int main()':
a.cc:72:20: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   72 |         if(!close[i][ni])v.push_back(P(0,cost)),cnt++;
      |                    ^
a.cc:72:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   72 |         if(!close[i][ni])v.push_back(P(0,cost)),cnt++;
      |                        ^