Language: C++

#include <algorithm>

namespace rika
{
  template <typename T>
  class edge
  {
  public:
    int to;
    T cost;
    
    edge() = default;
    edge(const edge<T>&) = default;
    edge(edge<T>&&) = default;
    edge& operator =(const edge<T>&) = default;
    edge& operator =(edge<T>&&) = default;

    ~edge() = default;

    edge(int _to, T _cost) : to(_to), cost(_cost) {}
  };
}
  int N;

#include<bits/stdc++.h>
using namespace std;
using namespace rika;
namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      if(v >= N)
        throw "test";
      auto r = std::make_pair(TValue(), v);
      try{
      for(auto it = g[v].begin(); it != g[v].end(); ++it)
      {
        if(it->to == from)
          continue;
        auto r2 = visit<TValue>(v, it->to, g);
        if(r2.first + it->cost >= r.first)
          r = std::make_pair(r2.first + it->cost, r2.second);
      }
      }catch(const std::out_of_range &e){throw "test";}
      return r;
    }
  }

  template <typename TValue, typename TGraph>
  TValue tree_diameter(const TGraph &g)
  {
    using namespace internal;
    auto r1 = visit<TValue>(-1, 0, g);
    auto r2 = visit<TValue>(-1, r1.second, g);
    return r2.first;
  }
}

#include<bits/stdc++.h>
using namespace std;
using namespace rika;
int main()#include <algorithm>

namespace rika
{
  template <typename T>
  class edge
  {
  public:
    int to;
    T cost;
    
    edge() = default;
    edge(const edge<T>&) = default;
    edge(edge<T>&&) = default;
    edge& operator =(const edge<T>&) = default;
    edge& operator =(edge<T>&&) = default;

    ~edge() = default;

    edge(int _to, T _cost) : to(_to), cost(_cost) {}
  };
}
  int N;

#include<bits/stdc++.h>
using namespace std;
using namespace rika;
namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      if(v >= N)
        throw "test";
      auto r = std::make_pair(TValue(), v);
      try{
      for(auto it = g[v].begin(); it != g[v].end(); ++it)
      {
        if(it->to == from)
          continue;
        auto r2 = visit<TValue>(v, it->to, g);
        if(r2.first + it->cost >= r.first)
          r = std::make_pair(r2.first + it->cost, r2.second);
      }
      }catch(const std::out_of_range &e){throw e;}
      return r;
    }
  }

  template <typename TValue, typename TGraph>
  TValue tree_diameter(const TGraph &g)
  {
    using namespace internal;
    auto r1 = visit<TValue>(-1, 0, g);
    auto r2 = visit<TValue>(-1, r1.second, g);
    return r2.first;
  }
}

#include<bits/stdc++.h>
using namespace std;
using namespace rika;
int main()
{
  cin >> N;
  vector<vector<edge<int>>> g(N * 10);
  for(int i = 0; i < N - 1; i++)
  {
    int s, t, w;
    cin >> s >> t >> w;
    g[s].push_back(edge<int>(t, w));
    g[t].push_back(edge<int>(s, w));
  }
  cout << tree_diameter<int>(g) << endl;
}
{
  cin >> N;
  vector<vector<edge<int>>> g(N * 10);
  for(int i = 0; i < N - 1; i++)
  {
    int s, t, w;
    cin >> s >> t >> w;
    g[s].push_back(edge<int>(t, w));
    g[t].push_back(edge<int>(s, w));
  }
  cout << tree_diameter<int>(g) << endl;
}

Compiler output:
a.cc:65:11: error: stray '#' in program
   65 | int main()#include <algorithm>
      |           ^
a.cc:65:12: error: expected initializer before 'include'
   65 | int main()#include <algorithm>
      |            ^~~~~~~
a.cc:87:7: error: redefinition of 'int N'
   87 |   int N;
      |       ^
a.cc:23:7: note: 'int N' previously declared here
   23 |   int N;
      |       ^
a.cc:97:28: error: redefinition of 'template<class TValue, class TGraph> std::pair<_BiIter, int> rika::internal::visit(int, int, const TGraph&)'
   97 |     std::pair<TValue, int> visit(int from, int v, const TGraph &g)
      |                            ^~~~~
a.cc:33:28: note: 'template<class TValue, class TGraph> std::pair<_BiIter, int> rika::internal::visit(int, int, const TGraph&)' previously declared here
   33 |     std::pair<TValue, int> visit(int from, int v, const TGraph &g)
      |                            ^~~~~
a.cc:117:10: error: redefinition of 'template<class TValue, class TGraph> TValue rika::tree_diameter(const TGraph&)'
  117 |   TValue tree_diameter(const TGraph &g)
      |          ^~~~~~~~~~~~~
a.cc:53:10: note: 'template<class TValue, class TGraph> TValue rika::tree_diameter(const TGraph&)' previously declared here
   53 |   TValue tree_diameter(const TGraph &g)
      |          ^~~~~~~~~~~~~
a.cc:142:1: error: expected unqualified-id before '{' token
  142 | {
      | ^