Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;
#define MOD 1000000007

struct Edge {
    int to; int w;
    Edge(int _to, int _w):to(_to),w(_w) {}
};

vector< vector<Edge> > G;
vector< int > dist;
int Root;

template <class T> struct TreeDiameter {
    
    
    
    
    TreeDiameter(int size){
        G.resize(size),dist.resize(size,-1);
    }
    
    void add_edge(int a, int b, T cost){
        G[a].push_back(Edge(b,cost));
        G[b].push_back(Edge(a,cost));
        Root = a;
    }
    
    void dfs(int v){
        stack< Edge > sta;
        sta.push(Edge(v,0));
        while(sta.size()!=0){
            Edge et = sta.top(); sta.pop();
            dist[et.to] = et.w;
            for(int i=0;i<G[et.to].size();i++){
                if(dist[G[et.to][i].to]<0){
                    sta.push(Edge(G[et.to][i].to,G[et.to][i].w+et.w));
                }
            }
        }
    }
    
    T getDiameter(){
        dfs(Root);
        int ver = -1;
        T d = -1;
        for(int i=0;i<dist.size();i++){
            if(dist[i]>d)d = dist[ver = i];
            dist[i] = -1;
        }
        dfs(ver);
        T ret = 0;
        for(int i=0;i<dist.size();i++)ret = max(ret,dist[i]);
        return ret;
    }
    
};

int main(){
    
    TreeDiameter<ll> inst(100010);
    int n; cin>>n;
    REP(i,n-1){
        int a,b,s;
        cin>>a>>b>>s;
        inst.add_edge(a,b,s);
    }
    
    cout<<inst.getDiameter()<<endl;
    
    return 0;
}

Compiler output:
a.cc: In instantiation of 'T TreeDiameter<T>::getDiameter() [with T = long long int]':
a.cc:90:27:   required from here
   90 |     cout<<inst.getDiameter()<<endl;
      |           ~~~~~~~~~~~~~~~~^~
a.cc:74:48: error: no matching function for call to 'max(long long int&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   74 |         for(int i=0;i<dist.size();i++)ret = max(ret,dist[i]);
      |                                             ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 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:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:74:48: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   74 |         for(int i=0;i<dist.size();i++)ret = max(ret,dist[i]);
      |                                             ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:74:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   74 |         for(int i=0;i<dist.size();i++)ret = max(ret,dist[i]);
      |                                             ~~~^~~~~~~~~~~~~