Language: C++

using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define infile "./test/sample-1.in"
// {{{ define basic macro
#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define foreach(x,a) for(auto& (x) : (a) )
#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
#define INF 2147483647
#define INFLL 1000000000000000000LL
#define MOD 1000000007
// }}}

// dump macro{{{
// http://www.creativ.xyz/dump-cpp-652
#define DUMPOUT cerr // 変数ダンプ先。coutかcerr

#ifdef PCM
// 引数はいくつでもどんな型でも可（ストリーム出力演算子があればOK）
#define dump(...) DUMPOUT<<"  "; \
  DUMPOUT<<#__VA_ARGS__; \
  DUMPOUT<<":=> "; \
  dump_func(__VA_ARGS__); DUMPOUT<<"in ["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;
#define dump_1d(x,n) DUMPOUT <<"  " \
  <<#x<<"["<<#n<<"]"<<":=> {"; \
  rep(i,n){ DUMPOUT << x[i] << (((i)==(n-1))?"}":", "); } DUMPOUT <<" in [" << __LINE__ << "]" << endl;

#define dump_2d(x,n,m) DUMPOUT <<"  " \
    <<#x<<"["<<#n<<"]"<<"["<<#m<<"]"<<":=> \n"; \
    rep(i,n)rep(j,m){ DUMPOUT << ((j==0)?"     |":" ") << x[i][j] << (((j)==(m-1))?"|\n":" "); } \
    DUMPOUT <<"  in [" << __LINE__ << "]" << endl;
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif

// デバッグ用変数ダンプ関数
void dump_func() {
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail)
{
    DUMPOUT << head;
    if (sizeof...(Tail) == 0) {
        DUMPOUT << " ";
    }
    else {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i<sz(vec); i++) {
        os << vec[i] << (i + 1 == sz(vec) ? "" : ", ");
    }
    os << "}";
    return os;
}/*}}}*/

struct Fast {  //{{{
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

// }}}

template <typename T>/*{{{*/
vector<T> dijkstra(ll s,vector<vector<pair<ll, T> > > & G,T I){
  using P = pair<T, ll>;
  ll n=G.size();
  vector<T> d(n,I);
  vector<ll> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  d[s]=0;
  q.emplace(d[s],s);
  while(!q.empty()){
    P p=q.top();q.pop();
    ll v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      ll u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
	d[u]=d[v]+c;
	b[u]=v;
	q.emplace(d[u],u);
      }
    }
  }
  return d;
}/*}}}*/

int solve(){
  int n,m;cin>>n>>m;
  int cnt[n]={};
  int u,v,s;

  using P = pair<ll, ll>;
  vector<vector<P> > G(m+1);
  rep(i, m){
    cin>>u>>v>>s;
    u--;v--;
    cnt[u]++;
    cnt[v]++;
    G[u].emplace_back(v,s);
    G[v].emplace_back(u,s);
  }

  dump_1d(cnt, n);

  vi x;
  rep(i, n){
    if (cnt[i]==1){ x.pb(i); }
  }
  if (sz(x)==0) {
    cout << 1 << endl;
    return 0;
  }

  auto d =dijkstra(x[0], G, INFLL);
  dump(x[0]);
  dump(d);
  ll res = INFLL;
  rep(i, sz(x)){
    res = min(res, d[x[i]]-(G[x[i]]-G[x[0]])-1);
  }
  cout << res << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Compiler output:
a.cc: In function 'int solve()':
a.cc:165:36: error: no match for 'operator-' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'std::vector<std::pair<long long int, long long int> >'} and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'std::vector<std::pair<long long int, long long int> >'})
  165 |     res = min(res, d[x[i]]-(G[x[i]]-G[x[0]])-1);
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:165:43: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'std::vector<std::pair<long long int, long long int> >'} is not derived from 'const std::reverse_iterator<_Iterator>'
  165 |     res = min(res, d[x[i]]-(G[x[i]]-G[x[0]])-1);
      |                                           ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:165:43: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'std::vector<std::pair<long long int, long long int> >'} is not derived from 'const std::move_iterator<_IteratorL>'
  165 |     res = min(res, d[x[i]]-(G[x[i]]-G[x[0]])-1);
      |                                           ^
In file included from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:3:
/usr/include/c++/14/complex:370:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&, const complex<_Tp>&)'
  370 |     operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:370:5: note:   template argument deduction/substitution failed:
a.cc:165:43: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'std::vector<std::pair<long long int, long long int> >'} is not derived from 'const std::complex<_Tp>'
  165 |     res = min(res, d[x[i]]-(G[x[i]]-G[x[0]])-1);
      |                                           ^
/usr/include/c++/14/complex:379:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&, const _Tp&)'
  379 |     operator-(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:379:5: note:   template argument deduction/substitution failed:
a.cc:165:43: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'std::vector<std::pair<long long int, long long int> >'} is not derived from 'const std::complex<_Tp>'
  165 |     res = min(res, d[x[i]]-(G[x[i]]-G[x[0]])-1);
      |                                           ^
/usr/include/c++/14/complex:388:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const _Tp&, const complex<_Tp>&)'
  388 |     operator-(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:388:5: note:   template argument deduction/substitution failed:
a.cc:165:43: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'std::vector<std::pair<long long int, long long int> >'} is not derived from 'const std::complex<_Tp>'
  165 |     res = min(res, d[x[i]]-(G[x[i]]-G[x[0]])-1);
      |                                           ^
/usr/include/c++/14/complex:465:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&)'
  465 |     operator-(const complex<_Tp>& __x)
      |     ^~~~~~~~
/usr/include/c++/14/complex:465:5: note:   candidate expects 1 argument, 2 provided
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:165:43: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'std::vector<std::pair<long long int, long long int> >'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  165 |     res = min(res, d[x[i]]-(G[x[i]]-G[x[0]])-1);
      |                                           ^
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:165:43: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'std::vector<std::pair<long long int, long long int> >'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  165 |     res = min(res, d[x[i]]-(G[x[i]]-G[x[0]])-1);
      |                                           ^
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:165:43: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'std::vector<std::pair<long long int, long long int> >'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  165 |     res = min(res, d[x[i]]-(G[x[i]]-G[x[0]])-1);
      |                                           ^
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:165:43: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'std::vector<std::pair<long long int, long long int> >'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  165 |     res = min(res, d[x[i]]-(G[x[i]]-G[x[0]])-1);
      |                                           ^
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__minus, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:165:43: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long