Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=4e5+51;
struct Edge{
	ll from,to;
	li dist;
	inline bool operator <(const Edge &rhs)const
	{
		return this->dist<rhs.dist;
	}
};
Edge ed[MAXN];
ll nc,cnt,x,y,z,tot;
li dist[MAXN],boss[MAXN];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
} 
inline void setup(ll cnt)
{
	for(register int i=0;i<cnt;i++)
	{
		boss[i]=i;
	}
}
inline void update()
{
	for(register int i=0;i<nc;i++)
	{
		dist[i]=min(dist[i],dist[(i+nc-1)%nc]+2);
	}
}
inline ll findb(ll node)
{
	if(node==boss[node])
	{
		return node;
	}
	boss[node]=findb(boss[node]);
	return boss[node];
}
inline void Union(ll x,ll y)
{
	ll bx=findb(x),by=findb(y);
	if(bx!=by)
	{
		boss[by]=bx;
	}
}
inline ll Kruskal()
{
	li res=0,k=0;
	sort(ed,ed+tot),setup(nc);
	for(register int i=0;k<nc-1;i++)
	{
		if(findb(ed[i].from)!=findb(ed[i].to))
		{
			Union(ed[i].from,ed[i].to),res+=ed[i].dist,k++;
		}
	}
	return res;
}
int main()
{
	nc=read(),cnt=read(),memset(dist,0x3f,sizeof(dist));
	for(register int i=0;i<cnt;i++)
	{
		x=read(),y=read(),z=read();
		ed[tot++]=(Edge){x,y,z};
		dist[x]=min(dist[x],z+1),dist[y]=min(dist[y],z+2);
	}
	update(),update();
	for(register int i=0;i<=nc;i++)
	{
		ed[tot++]=(Edge){i,(i+1)%nc,dist[i]};
	}
	printf("%lld",Kruskal());
}

Compiler output:
a.cc: In function 'll read()':
a.cc:19:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 |     register ll num=0,neg=1;
      |                 ^~~
a.cc:19:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 |     register ll num=0,neg=1;
      |                       ^~~
a.cc:20:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   20 |     register char ch=getchar();
      |                   ^~
a.cc: In function 'void setup(ll)':
a.cc:39:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   39 |         for(register int i=0;i<cnt;i++)
      |                          ^
a.cc: In function 'void update()':
a.cc:46:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   46 |         for(register int i=0;i<nc;i++)
      |                          ^
a.cc: In function 'll Kruskal()':
a.cc:72:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   72 |         for(register int i=0;k<nc-1;i++)
      |                          ^
a.cc: In function 'int main()':
a.cc:84:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   84 |         for(register int i=0;i<cnt;i++)
      |                          ^
a.cc:88:28: error: no matching function for call to 'min(li&, ll)'
   88 |                 dist[x]=min(dist[x],z+1),dist[y]=min(dist[y],z+2);
      |                         ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/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:88:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'll' {aka 'int'})
   88 |                 dist[x]=min(dist[x],z+1),dist[y]=min(dist[y],z+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
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:88:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   88 |                 dist[x]=min(dist[x],z+1),dist[y]=min(dist[y],z+2);
      |                         ~~~^~~~~~~~~~~~~
a.cc:88:53: error: no matching function for call to 'min(li&, ll)'
   88 |                 dist[x]=min(dist[x],z+1),dist[y]=min(dist[y],z+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:88:53: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'll' {aka 'int'})
   88 |                 dist[x]=min(dist[x],z+1),dist[y]=min(dist[y],z+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:88:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   88 |                 dist[x]=min(dist[x],z+1),dist[y]=min(dist[y],z+2);
      |                                                  ~~~^~~~~~~~~~~~~
a.cc:91:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   91 |         for(register int i=0;i<=nc;i++)
      |                          ^