Language: C++

#include <bits/stdc++.h>
#define MAXN 210000
#define ll long long
#define INF (1<<30) 
using namespace std;
ll n,q;
struct data{
	ll u,v,w;
}line[MAXN*2];
ll link[MAXN*2];

inline ll read(){
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

inline bool cmp(data a,data b){
	return a.w<b.w;
}

ll fa[MAXN];

ll find(ll x){
	if (fa[x]==x)
		return x;
	return fa[x]=find(fa[x]);
}
int main(){
	n=read(),q=read();
	for(ll i=0;i<2*n;i++)
		link[i]=line[q+i].w=INF;
	for(ll i=1;i<=q;i++){
		ll a=read(),b=read(),c=read();
		line[i].u=a,line[i].v=b,line[i].w=c;
		
		link[a]=min(link[a],c+1);
		link[b]=min(link[b],c+2);
	}
	ll minn=INF;
	for(ll i=0;i<2*n-1;i++){
		minn+=2;
		minn=min(link[i],minn);
		line[q+(i%n)+1].u=i%n;
		line[q+(i%n)+1].v=(i+1)%n;
		line[q+(i%n)+1].w=min(line[q+(i%n)+1].w,minn);
	}
	sort(line+1,line+1+n+q,cmp);
	ll cnt=0,sum=0;
	for(int i=0;i<n;i++)
		fa[i]=i; 
	for(ll i=1;cnt<n-1;i++){
		ll xf=find(line[i].u),yf=find(line[i].v);
		if (xf!=yf){
			//cout<<line[i].u<<" "<<line[i].v<<" "<<line[i].w<<endl;
			cnt++;
			fa[xf]=yf;
			sum+=line[i].w;
		}
	}
	cout<<sum;
	return 0;
}

Compiler output:
a.cc:10:15: error: 'long long int link [420000]' redeclared as different kind of entity
   10 | ll link[MAXN*2];
      |               ^
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:819:12: note: previous declaration 'int link(const char*, const char*)'
  819 | extern int link (const char *__from, const char *__to)
      |            ^~~~
a.cc:27:17: error: reference to 'data' is ambiguous
   27 | inline bool cmp(data a,data b){
      |                 ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:8: note:                 'struct data'
    7 | struct data{
      |        ^~~~
a.cc:27:24: error: reference to 'data' is ambiguous
   27 | inline bool cmp(data a,data b){
      |                        ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:8: note:                 'struct data'
    7 | struct data{
      |        ^~~~
a.cc:27:30: error: expression list treated as compound expression in initializer [-fpermissive]
   27 | inline bool cmp(data a,data b){
      |                              ^
a.cc: In function 'int main()':
a.cc:41:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   41 |                 link[i]=line[q+i].w=INF;
      |                       ^
a.cc:41:24: error: assignment of read-only location '*(link + ((sizetype)i))'
   41 |                 link[i]=line[q+i].w=INF;
      |                        ^
a.cc:46:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   46 |                 link[a]=min(link[a],c+1);
      |                       ^
a.cc:46:35: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   46 |                 link[a]=min(link[a],c+1);
      |                                   ^
a.cc:46:28: error: no matching function for call to 'min(int (&)(const char*, const char*) noexcept, long long int)'
   46 |                 link[a]=min(link[a],c+1);
      |                         ~~~^~~~~~~~~~~~~
In file included 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/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:46:28: note:   deduced conflicting types for parameter 'const _Tp' ('int(const char*, const char*) noexcept' and 'long long int')
   46 |                 link[a]=min(link[a],c+1);
      |                         ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:46:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int (*)(const char*, const char*) noexcept'
   46 |                 link[a]=min(link[a],c+1);
      |                         ~~~^~~~~~~~~~~~~
a.cc:47:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   47 |                 link[b]=min(link[b],c+2);
      |                       ^
a.cc:47:35: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   47 |                 link[b]=min(link[b],c+2);
      |                                   ^
a.cc:47:28: error: no matching function for call to 'min(int (&)(const char*, const char*) noexcept, long long int)'
   47 |                 link[b]=min(link[b],c+2);
      |                         ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:47:28: note:   deduced conflicting types for parameter 'const _Tp' ('int(const char*, const char*) noexcept' and 'long long int')
   47 |                 link[b]=min(link[b],c+2);
      |                         ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:47:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int (*)(const char*, const char*) noexcept'
   47 |                 link[b]=min(link[b],c+2);
      |                         ~~~^~~~~~~~~~~~~
a.cc:52:32: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   52 |                 minn=min(link[i],minn);
      |                                ^
a.cc:52:25: error: no matching function for call to 'min(int (&)(const char*, const char*) noexcept, long long int&)'
   52 |                 minn=min(link[i],minn);
      |                      ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:52:25: note:   deduced conflicting types for parameter 'const _Tp' ('int(const char*, const char*) noexcept' and 'long long int')
   52 |                 minn=min(link[i],minn);
      |                      ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:52:25: note:   mismatched types 'std::i