criyle/codenet-compile-errors huggingface dataset:
Language: Java

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;


public class GRL_5_A_DiameterOfTree {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();

		init(n);
		for (int i=0;i<n-1;i++) {
			int s = in.nextInt();
			int t = in.nextInt();
			int w = in.nextInt();
			// bidirectional
			adList[s].add(new P(t, w));
			adList[t].add(new P(s, w));
		}
		
		System.out.println(getFurthest().dist);
	}

	static List<P>[] adList;
	static long[] dist;
	static P getFurthest() { // return P have index and furthest distance
		dijkstra(0);
		long furthest = -1;
		int furthestIdx = -1;
		for (int i=0;i<dist.length;i++) {
			if (furthest < dist[i]) {
				furthest = dist[i];
				furthestIdx = i;
			}
		}
		Arrays.fill(dist, Long.MAX_VALUE);
		dijkstra(furthestIdx);
		furthest = -1;
		furthestIdx = -1;
		for (int i=0;i<dist.length;i++) {
			if (furthest < dist[i]) {
				furthest = dist[i];
				furthestIdx = i;
			}
		}
		return new P(furthestIdx, furthest);
	}
	static void dijkstra(int s) { // s is start
		dist[s] = 0L;
		PriorityQueue<P> q = new PriorityQueue<P>();
		q.add(new P(s, 0L));
		
		while (!q.isEmpty()) {
			P cur = q.poll();
			if (dist[cur.index] < cur.dist)
				continue;
			for (P next : adList[cur.index]) {
				if (dist[next.index] > dist[cur.index] + next.dist) {
					dist[next.index] = dist[cur.index] + next.dist;
					q.add(new P(next.index, dist[next.index]));
				}
			}
		}
	}
	@SuppressWarnings("unchecked")
	static void init(int n) {
		adList = new List[n];
		for (int i=0;i<n;i++) {
			adList[i] = new ArrayList<P>();
		}
		dist = new long[n];
		Arrays.fill(dist, Long.MAX_VALUE);
	}
	static class P implements Comparable<P> {
		int index; long dist;
		public P(int index, long dist) {this.index = index; this.dist = dist;}
		public int compareTo(P p) {return this.dist < p.dist ? -1 : this.dist == p.dist ? 0 : 1;}
		public String toString() {return index+","+dist;}
	}
	// in adList, P.dist is distance from adjacent point
	// in q, P.dist is shortest path distance from start point
}

Compiler output:
Main.java:8: error: class GRL_5_A_DiameterOfTree is public, should be declared in a file named GRL_5_A_DiameterOfTree.java
public class GRL_5_A_DiameterOfTree {
       ^
1 error
Language: Java

import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
 
    static long x = 0;
    public static void main(String[] args) {
    	try {
	        Scanner sc = new Scanner(System.in);
	          int n= sc.nextInt();
	//        cin >> n;
	          
	          ArrayList<node> tree = new ArrayList<>();
	          for (int i = 0; i < n; i++) {
	              tree.add(new node());
	          }
	          
	          for (int i = 0, s, t, w; i < n - 1; i++) {
	//          cin >> s >> t >> w;
	            s = sc.nextInt();
	            t = sc.nextInt();
	            w = sc.nextInt();
	          
	            tree.get(s).next.add(new edge(w, t));
	            tree.get(t).next.add(new edge(w, s));
	          }
	          
	          solve(tree, 0);
	//        cout << tree.get(0).diameter << endl;
	         System.out.println(tree.get(0).diameter);
    	} catch (StackOverFlowError e) {
    		System.out.println(-2);
    	}
    }
 
     
    static class edge {
          int weight;
          int nodeIdx;
          edge(int w, int i) {
            weight = w;
            nodeIdx = i;
          }
        }
          
    static class node {
          ArrayList<edge> next = new ArrayList<>();
          int height;
          int diameter;
          boolean visited;
          
          node() {
            height = 0;
            diameter = 0;
            visited = false;
          }
        }
          
        static void solve(ArrayList<node> tree, int idx) {
          //cout << "called for node: " << idx << endl;
          // if (tree.get(idx).visited) return;
          tree.get(idx).visited = true;
          
          int bestHeight  = 0, bestHeight2 = 0, bestDiameter = 0;
          
          for (int i = 0; i < tree.get(idx).next.size(); i++) {
            int nextIdx = tree.get(idx).next.get(i).nodeIdx;
            if (tree.get(nextIdx).visited) continue;
          
            //cout << idx << " next-> " << nextIdx << endl;
            solve(tree, nextIdx);
          
            bestDiameter = Math.max(bestDiameter, tree.get(nextIdx).diameter);
            int h = tree.get(nextIdx).height + tree.get(idx).next.get(i).weight;
          
            if (h > bestHeight) {
              bestHeight2 = bestHeight;
              bestHeight = h;
            } else if (h > bestHeight2) {
              bestHeight2 = h;
            }
          }
          
          tree.get(idx).height = bestHeight;
          tree.get(idx).diameter = Math.max(bestDiameter, bestHeight + bestHeight2);
          //cout << "Node: " << idx << " H: " << tree.get(idx).height << " D: " << tree.get(idx).diameter << " bestDiameter: " << bestDiameter << endl << endl;
        }
}


Compiler output:
Main.java:31: error: cannot find symbol
    	} catch (StackOverFlowError e) {
    	         ^
  symbol:   class StackOverFlowError
  location: class Main
1 error
Language: C

#include <stdio.h>
#include <stdlib.h>

#define MAX_N 100000
#define INF 10000000

typedef struct {
	int to, dist;
}P;

P graph[MAX_N][16];
int graphptr[MAX_N];

int n;

typedef struct {
	int prior;
	P data;
} node_t;

typedef struct {
	node_t *nodes;
	int len;
	int size;
} heap_t;

void push(heap_t *h, int prior, P data) {
	if (h->len + 1 >= h->size) {
		h->size = h->size ? h->size * 2 : 4;
		h->nodes = (node_t*)realloc(h->nodes, h->size * sizeof(node_t));
	}
	int i = h->len + 1;
	int j = i / 2;
	while (i > 1 && h->nodes[j].prior > prior) {
		h->nodes[i] = h->nodes[j];
		i = j;
		j /= 2;
	}
	h->nodes[i].prior = prior;
	h->nodes[i].data = data;
	h->len++;
}

P pop(heap_t *h) {
	int i, j, k;
	if (!h->len) {
		P p;
		p.to = -1; p.dist = -1;
		return p;
	}
	P data = h->nodes[1].data;
	h->nodes[1] = h->nodes[h->len];
	h->len--;
	i = 1;
	while (true) {
		k = i;
		j = 2 * i;
		if (j <= h->len && h->nodes[j].prior < h->nodes[k].prior) k = j;
		if (j + 1 <= h->len && h->nodes[j + 1].prior < h->nodes[k].prior)k = j + 1;
		if (k == i)break;
		h->nodes[i] = h->nodes[k];
		i = k;
	}
	h->nodes[i] = h->nodes[h->len + 1];
	return data;
}

int cost[MAX_N];

void dijkstra(int k) {
	heap_t *h = (heap_t*)calloc(1, sizeof(heap_t));
	for (int i = 0; i < n; ++i)cost[i] = INF;
	cost[k] = 0;
	P t;
	t.to = k, t.dist = 0;
	push(h, t.dist, t);
	while (h->len) {
		P p = pop(h);
		int v = p.to;
		if (cost[v] < p.dist)continue;
		for (int i = 0; i < graphptr[v]; ++i) {
			P e = graph[v][i];
			if (cost[e.to] > cost[v] + e.dist) {
				cost[e.to] = cost[v] + e.dist;
				P m;
				m.to = e.to; m.dist = cost[e.to];
				push(h, m.dist, m);
			}
		}
	}
}

int treeDim_C(P *ret) {
	dijkstra(0);

	int maxV = -INF, maxI;
	for (int i = 0; i < n; ++i) {
		if (cost[i] > maxV)maxV = cost[i], maxI = i;
	}

	dijkstra(maxI);

	ret->to = maxI;

	maxV = -INF, maxI;
	for (int i = 0; i < n; ++i) {
		if (cost[i] > maxV)maxV = cost[i], maxI = i;
	}

	ret->dist = maxI;
	return maxV;
}

int main(void) {
	scanf("%d", &n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);

		graph[a][graphptr[a]].to = b;
		graph[a][graphptr[a]++].dist = c;

		graph[b][graphptr[b]].to = a;
		graph[b][graphptr[b]++].dist = c;
	}

	P p;
	printf("%d\n", treeDim_C(&p));

	return 0;
}

Compiler output:
main.c: In function 'pop':
main.c:55:16: error: 'true' undeclared (first use in this function)
   55 |         while (true) {
      |                ^~~~
main.c:3:1: note: 'true' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
    2 | #include <stdlib.h>
  +++ |+#include <stdbool.h>
    3 | 
main.c:55:16: note: each undeclared identifier is reported only once for each function it appears in
   55 |         while (true) {
      |                ^~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

vector<int> dist;
vector<vector<edge>> e;
int N;

struct edge {
    int to;
    int cost;
    edge(int a, int b) : to(a), cost(b) {}
};

int dfs1(int p, int par = -1)
{
    int& res = dist[p];
    for (auto x : e[p]) {
        if (x.to == par) continue;
        res = max(res, x.cost + dfs1(x.to, p));
    }
    return res;
}

int dfs2(int p, int d_par = 0, int par = -1)
{
    vector<pair<int, int>> d;
    d.emplace_back(0, -1);
    for (auto x : e[p]) {
        if (x.to == par) d.emplace_back(d_par + x.cost, x.to);
        else d.emplace_back(dist[x.to] + x.cost, x.to);
    }
    sort(d.rbigin(), d.rend());
    int res = d[0].first + d[1].first;
    for (auto x : e[p]) {
        if (x.to == par) continue;
        res = max(res, dfs2(x.to, d[x.to == d[0].second], p));
    }
    return res;
}

int main()
{
    cin >> N;
    dist.resize(N, 0);
    e.resize(N);
    for (int i = 0; i < N-1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        e[s].emplace_back(t, w);
        e[t].emplace_back(s, w);
    }
    dfs1(N / 2);
    cout << dfs2(N / 2) << endl;
}


Compiler output:
a.cc:6:15: error: 'edge' was not declared in this scope
    6 | vector<vector<edge>> e;
      |               ^~~~
a.cc:6:15: error: template argument 1 is invalid
a.cc:6:15: error: template argument 2 is invalid
a.cc:6:19: error: template argument 1 is invalid
    6 | vector<vector<edge>> e;
      |                   ^~
a.cc:6:19: error: template argument 2 is invalid
a.cc: In function 'int dfs1(int, int)':
a.cc:18:20: error: invalid types 'int[int]' for array subscript
   18 |     for (auto x : e[p]) {
      |                    ^
a.cc: In function 'int dfs2(int, int, int)':
a.cc:29:20: error: invalid types 'int[int]' for array subscript
   29 |     for (auto x : e[p]) {
      |                    ^
a.cc:33:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'rbigin'; did you mean 'rbegin'?
   33 |     sort(d.rbigin(), d.rend());
      |            ^~~~~~
      |            rbegin
a.cc:35:20: error: invalid types 'int[int]' for array subscript
   35 |     for (auto x : e[p]) {
      |                    ^
a.cc: In function 'int main()':
a.cc:46:7: error: request for member 'resize' in 'e', which is of non-class type 'int'
   46 |     e.resize(N);
      |       ^~~~~~
a.cc:50:10: error: invalid types 'int[int]' for array subscript
   50 |         e[s].emplace_back(t, w);
      |          ^
a.cc:51:10: error: invalid types 'int[int]' for array subscript
   51 |         e[t].emplace_back(s, w);
      |          ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

struct edge {
    int to;
    int cost;
    edge(int a, int b) : to(a), cost(b) {}
};


vector<int> dist;
vector<vector<edge>> e;
int N;

int dfs1(int p, int par = -1)
{
    int& res = dist[p];
    for (auto x : e[p]) {
        if (x.to == par) continue;
        res = max(res, x.cost + dfs1(x.to, p));
    }
    return res;
}

int dfs2(int p, int d_par = 0, int par = -1)
{
    vector<pair<int, int>> d;
    d.emplace_back(0, -1);
    for (auto x : e[p]) {
        if (x.to == par) d.emplace_back(d_par + x.cost, x.to);
        else d.emplace_back(dist[x.to] + x.cost, x.to);
    }
    sort(d.rbigin(), d.rend());
    int res = d[0].first + d[1].first;
    for (auto x : e[p]) {
        if (x.to == par) continue;
        res = max(res, dfs2(x.to, d[x.to == d[0].second], p));
    }
    return res;
}

int main()
{
    cin >> N;
    dist.resize(N, 0);
    e.resize(N);
    for (int i = 0; i < N-1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        e[s].emplace_back(t, w);
        e[t].emplace_back(s, w);
    }
    dfs1(N / 2);
    cout << dfs2(N / 2) << endl;
}


Compiler output:
a.cc: In function 'int dfs2(int, int, int)':
a.cc:34:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'rbigin'; did you mean 'rbegin'?
   34 |     sort(d.rbigin(), d.rend());
      |            ^~~~~~
      |            rbegin
a.cc:38:28: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int'
   38 |         res = max(res, dfs2(x.to, d[x.to == d[0].second], p));
      |                        ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                            |
      |                            __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type {aka std::pair<int, int>}
a.cc:26:21: note:   initializing argument 2 of 'int dfs2(int, int, int)'
   26 | int dfs2(int p, int d_par = 0, int par = -1)
      |                 ~~~~^~~~~~~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

struct edge {
    int to;
    int cost;
    edge(int a, int b) : to(a), cost(b) {}
};

vector<vector<edge>> e;
int N;

pair<int, int> dfs(int p, int par = -1)
{
    if (e[p].size() == 1 && par >= 0) {
        return make_pair(0, p);
    }
    pair<int, int> res = make_pair(-1, 0);
    for (auto x : e[p]) {
        if (x.to == par) continue;
        auto t = dfs(x.to, p);
        if (t.first + x.cost > res.first) {
            res.first = t.first + x.cost;
            res.second = t.second;
        }
    }
    return res;
}

int main()
{
    cin >> N;
    dist.resize(N, 0);
    e.resize(N);
    for (int i = 0; i < N-1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        e[s].emplace_back(t, w);
        e[t].emplace_back(s, w);
    }
    auto res = dfs(0);
    res = dfs(res.second);
    cout << res.first << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:5: error: 'dist' was not declared in this scope
   34 |     dist.resize(N, 0);
      |     ^~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

struct edge {
    int to;
    int cost;
    edge(int a, int b) : to(a), cost(b) {}
};

vector<vector<edge>> e;
int N;

pair<int, int> dfs(int p, int par = -1)
{
    pair<int, int> res = make_pair(0, p);
    for (auto x : e[p]) {
        if (x.to == par) continue;
        auto t = dfs(x.to, p);
        t.cost += x.cost;
        res = max(res, t);
    }
    return res;
}

int main()
{
    cin >> N;
    e.resize(N);
    for (int i = 0; i < N-1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        e[s].emplace_back(t, w);
        e[t].emplace_back(s, w);
    }
    auto res = dfs(0);
    res = dfs(res.second);
    cout << res.first << endl;
}


Compiler output:
a.cc: In function 'std::pair<int, int> dfs(int, int)':
a.cc:20:11: error: 'struct std::pair<int, int>' has no member named 'cost'
   20 |         t.cost += x.cost;
      |           ^~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

struct edge {
    int to;
    int cost;
    edge(int a, int b) : to(a), cost(b) {}
};

vector<vector<edge>> e;
int N;

pair<int, int> dfs(int p, int par = -1)
{
    if (e[p].size() == 1 && par >= 0) return make_pair(0, p);
    pair<int, int> res = make_pair(-1, -1);
    for (auto x : e[p]) {
        if (x.to == par) continue;
        auto t = dfs(x.to, p);
        t.first += x.cost;
        res = max(res, t);
        cnt++;
    }
    return res;
}

int main()
{
    cin >> N;
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    e.resize(N);
    for (int i = 0; i < N-1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        e[s].emplace_back(t, w);
        e[t].emplace_back(s, w);
    }
    auto res = dfs(0);
    res = dfs(res.second);
    cout << res.first << endl;
}


Compiler output:
a.cc: In function 'std::pair<int, int> dfs(int, int)':
a.cc:23:9: error: 'cnt' was not declared in this scope; did you mean 'int'?
   23 |         cnt++;
      |         ^~~
      |         int
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) {}
  };
}
 
namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      auto r = std::make_pair(TValue(), v);
      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);
      }
      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()
{
  int N;
  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: In function 'TValue rika::tree_diameter(const TGraph&)':
a.cc:50:12: error: 'r2' was not declared in this scope; did you mean 'r1'?
   50 |     return r2.first;
      |            ^~
      |            r1
Language: C++

#include <algorithm>

int N;
cin >> N;

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) {}
  };
}
 
namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      auto r = std::make_pair(TValue(), v);
      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);
      }
      return r;
    }
  }
 
  template <typename TValue, typename TGraph>
  TValue tree_diameter(const TGraph &g)
  {
    using namespace internal;
    auto r1 = visit<TValue>(-1, 0, g);
    if(0>r1.second||r1.second>=N) exit();
    auto r2 = visit<TValue>(-1, r1.second, g);
    return r2.first;
  }
}
 
#include<bits/stdc++.h>
using namespace std;
using namespace rika;
int main()
{
  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:4:1: error: 'cin' does not name a type
    4 | cin >> N;
      | ^~~
a.cc: In function 'TValue rika::tree_diameter(const TGraph&)':
a.cc:52:39: error: too few arguments to function 'void exit(int)'
   52 |     if(0>r1.second||r1.second>=N) exit();
      |                                   ~~~~^~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/bits/stl_algo.h:71,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:1:
/usr/include/stdlib.h:756:13: note: declared here
  756 | extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
      |             ^~~~
Language: C++

#include <algorithm>

int N;

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) {}
  };
}
 
namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      auto r = std::make_pair(TValue(), v);
      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);
      }
      return r;
    }
  }
 
  template <typename TValue, typename TGraph>
  TValue tree_diameter(const TGraph &g)
  {
    using namespace internal;
    auto r1 = visit<TValue>(-1, 0, g);
    if(0>r1.second||r1.second>=N) exit();
    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;
}

Compiler output:
a.cc: In function 'TValue rika::tree_diameter(const TGraph&)':
a.cc:51:39: error: too few arguments to function 'void exit(int)'
   51 |     if(0>r1.second||r1.second>=N) exit();
      |                                   ~~~~^~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/bits/stl_algo.h:71,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:1:
/usr/include/stdlib.h:756:13: note: declared here
  756 | extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
      |             ^~~~
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 ) {}
	};
}

namespace rika
{
	namespace internal
	{
		template <typename TValue, typename TGraph>
		std::pair<TValue, int> visit( int from, int v, const TGraph &g )
		{
			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 ( bool x ) {
				cout << "hoge" << endl;
			}
			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()
{
	int N;
	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: In function 'std::pair<TValue, int> rika::internal::visit(int, int, const TGraph&)':
a.cc:44:33: error: 'cout' was not declared in this scope
   44 |                                 cout << "hoge" << endl;
      |                                 ^~~~
a.cc:44:51: error: 'endl' was not declared in this scope
   44 |                                 cout << "hoge" << endl;
      |                                                   ^~~~
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) {}
  };
}
 
namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      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 (edge x) {}
      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()
{
  int N;
  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: In function 'std::pair<TValue, int> rika::internal::visit(int, int, const TGraph&)':
a.cc:42:14: error: missing template argument list after 'rika::edge'; template placeholder not permitted in parameter
   42 |       catch (edge x) {}
      |              ^~~~
      |                  <>
a.cc:6:9: note: 'template<class T> class rika::edge' declared here
    6 |   class edge
      |         ^~~~
Language: C++

#include <algorithm>
#include <cstdio>

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 ) {}
	};
}

namespace rika
{
	namespace internal
	{
		template <typename TValue, typename TGraph>
		std::pair<TValue, int> visit( int from, int v, const TGraph &g )
		{
			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 );
				}
			}
			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()
{
	int N;
	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: In function 'std::pair<TValue, int> rika::internal::visit(int, int, const TGraph&)':
a.cc:44:32: error: expected 'catch' before 'r'
   44 |                         return r;
      |                                ^
a.cc:44:32: error: expected '(' before 'r'
   44 |                         return r;
      |                                ^
      |                                (
a.cc:44:32: error: 'r' does not name a type
a.cc:44:33: error: expected ')' before ';' token
   44 |                         return r;
      |                                ~^
      |                                 )
a.cc:44:33: error: expected '{' before ';' token
a.cc: In instantiation of 'std::pair<TValue, int> rika::internal::visit(int, int, const TGraph&) [with TValue = int; TGraph = std::vector<std::vector<rika::edge<int> > >]':
a.cc:52:26:   required from 'TValue rika::tree_diameter(const TGraph&) [with TValue = int; TGraph = std::vector<std::vector<edge<int> > >]'
   52 |                 auto r1 = visit<TValue>( -1, 0, g );
      |                           ~~~~~~~~~~~~~^~~~~~~~~~~~
a.cc:73:28:   required from here
   73 |         cout << tree_diameter<int>( g ) << endl;
      |                 ~~~~~~~~~~~~~~~~~~^~~~~
a.cc:45:17: warning: no return statement in function returning non-void [-Wreturn-type]
   45 |                 }
      |                 ^
Language: C++

#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

const pii Dir[8] = { //?????????
	{ 0,1 },{ 0,-1 },{ 1,0 },{ -1,0 },
	{ 1,1 },{ 1,-1 },{ -1,-1 },{ -1,1 }
};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
int r;
vector<ll> v;
ll c = 1, n, k;

class Graph {
public:
	int vn;
	vector<vector<pii>> g;
	vector<int> depth;

	Graph(int n) {
		vn = n;
		g.resize(n);
	}
	void con(int a, int b, int w = 1) {
		g[a].push_back({ b,w });
		g[b].push_back({ a, w });
		
	}
};



int TDiam(Graph& graph) {
	vector<bool> al(graph.vn);
	function<pii(int,int)> func = [&](int cur, int dis) {
		pii Max = { dis,cur };
		al[cur] = 1;
		REP(i, graph.g[cur].size()) {
			if (!al[graph.g[cur][i].first]) {
				Max = max(Max,func(graph.g[cur][i].first, dis+graph.g[cur][i].second));
			}
		}

		return Max;
	};

	pii S = func(0,0);
	al.swap(vector<bool>(graph.vn));
	pii G = func(S.second,0);

	return G.first;
}

signed main() {
	int n;
	scanf("%d", &n);

	Graph graph(n);

	REP(i, n-1) {
		int a, b, w;
		scanf("%d %d %d", &a, &b, &w);
		//a--; b--;
		graph.con(a, b,w);
	}

	printf("%d\n", TDiam(graph));

	return 0;
}

Compiler output:
a.cc: In function 'int TDiam(Graph&)':
a.cc:80:17: error: cannot bind non-const lvalue reference of type 'std::vector<bool>&' to an rvalue of type 'std::vector<bool>'
   80 |         al.swap(vector<bool>(graph.vn));
      |                 ^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:67,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_bvector.h:1165:20: note:   initializing argument 1 of 'void std::vector<bool, _Alloc>::swap(std::vector<bool, _Alloc>&) [with _Alloc = std::allocator<bool>]'
 1165 |       swap(vector& __x) _GLIBCXX_NOEXCEPT
      |            ~~~~~~~~^~~
Language: C++

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define MAX 100000 //??¨?????\?????°????????§???
#define INFTY (1 << 30)

//???????????????
class Edge
{
public :
	int t, w;//???????????£?????????????????????
	Edge(){}
	Edge(int t, int w) :t(t), w(w) {}
};

vector<Edge> G[MAX];
int n, d[MAX];//??¨?????\?????°??????????????¢?´¢???????§??????????????????¢

bool vis[MAX];
int cnt;

void bfs(int s) 
{
	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
	}

	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	int u;

	while (!Q.empty()) {
		u = Q.front();
		Q.pop();

		for (int i = 0; i < G[u].size(); i++) {
			Edge e = G[u][i];
			if (d[e.t] == INFTY) {
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

long long diamterOfTree()
{
	bfs(0);
	long long maxv = 0;
	int tgt = 0;

	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) {
			continue;
		}
		if (maxv < d[i]) {
			maxv = d[i];
			tgt = i;
		}
	}

	//??????????????????????????????????????????????????¢?´¢??§?????¢????±???????
	bfs(tgt);

	maxv = 0;

	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) {
			continue;
		}
		if (maxv < d[i]) {
			maxv = d[i];
		}
	}

	return maxv;

}

void main(void)
{
	int s, t, w;
	cin >> n;


	//n-1?????????????????°????????§???????????????????????????????????\???????????±????????????????????\????????????????????????
	for (int i = 0; i < n - 1; i++) {
		cin >> s >> t >> w;

		G[s].push_back(Edge(t, w));
		G[t].push_back(Edge(t, w));
	}



}

Compiler output:
a.cc:84:1: error: '::main' must return 'int'
   84 | void main(void)
      | ^~~~
Language: C++

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define MAX 100000 //??¨?????\?????°????????§???
#define INFTY (1 << 30)

//???????????????
class Edge
{
public :
	int t, w;//???????????£?????????????????????
	Edge(){}
	Edge(int t, int w) :t(t), w(w) {}
};

vector<Edge> G[MAX];
int n, d[MAX];//??¨?????\?????°??????????????¢?´¢???????§??????????????????¢

bool vis[MAX];
int cnt;

void bfs(int s) 
{
	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
	}

	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	int u;

	while (!Q.empty()) {
		u = Q.front();
		Q.pop();

		for (int i = 0; i < G[u].size(); i++) {
			Edge e = G[u][i];
			if (d[e.t] == INFTY) {
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

int diamterOfTree()
{
	bfs(0);
	int maxv = 0;
	int tgt = 0;

	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) {
			continue;
		}
		if (maxv < d[i]) {
			maxv = d[i];
			tgt = i;
		}
	}

	//??????????????????????????????????????????????????¢?´¢??§?????¢????±???????
	bfs(tgt);

	maxv = 0;

	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) {
			continue;
		}
		if (maxv < d[i]) {
			maxv = d[i];
		}
	}

	return maxv;

}

void main(void)
{
	int s, t, w;
	cin >> n;


	//n-1?????????????????°????????§???????????????????????????????????\???????????±????????????????????\????????????????????????
	for (int i = 0; i < n - 1; i++) {
		cin >> s >> t >> w;

		G[s].push_back(Edge(t, w));
		G[t].push_back(Edge(t, w));
	}

	cout << diamterOfTree() << endl;

}

Compiler output:
a.cc:84:1: error: '::main' must return 'int'
   84 | void main(void)
      | ^~~~
Language: C++

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define MAX 100000 //??¨?????\?????°????????§???
#define INFTY (1 << 30)

//???????????????
class Edge
{
public :
	int t, w;//???????????£?????????????????????
	Edge(){}
	Edge(int t, int w) :t(t), w(w) {}
};

vector<Edge> G[MAX];
int n, d[MAX];//??¨?????\?????°??????????????¢?´¢???????§??????????????????¢

bool vis[MAX];
int cnt;

void bfs(int s) 
{
	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
	}

	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	int u;

	while (!Q.empty()) {
		u = Q.front();
		Q.pop();

		for (int i = 0; i < G[u].size(); i++) {
			Edge e = G[u][i];
			if (d[e.t] == INFTY) {
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

int diamterOfTree()
{
	bfs(0);
	int maxv = 0;
	int tgt = 0;

	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) {
			continue;
		}
		if (maxv < d[i]) {
			maxv = d[i];
			tgt = i;
		}
	}

	//??????????????????????????????????????????????????¢?´¢??§?????¢????±???????
	bfs(tgt);

	maxv = 0;

	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) {
			continue;
		}
		if (maxv < d[i]) {
			maxv = d[i];
		}
	}

	return maxv;

}

void main(void)
{
	int s, t, w;
	cin >> n;


	//n-1?????????????????°????????§???????????????????????????????????\???????????±????????????????????\????????????????????????
	for (int i = 0; i < n - 1; i++) {
		cin >> s >> t >> w;

		G[s].push_back(Edge(t, w));
		G[t].push_back(Edge(s, w));
	}

	cout << diamterOfTree() << endl;

}

Compiler output:
a.cc:84:1: error: '::main' must return 'int'
   84 | void main(void)
      | ^~~~
Language: C++

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

//??¨?????\?????°????????§???
#define MAX 100000 
#define INFTY (1 << 30)

//???????????????
class Edge
{
public :
	int t, w;//???????????£?????????????????????
	Edge(){}
	Edge(int t, int w) :t(t), w(w) {}
};

vector<Edge> G[MAX];
int n, d[MAX];//??¨?????\?????°??????????????¢?´¢???????§??????????????????¢

bool vis[MAX];
int cnt;

void bfs(int s) 
{
	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
	}

	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	int u;

	while (!Q.empty()) {
		u = Q.front();
		Q.pop();

		for (int i = 0; i < G[u].size(); i++) {
			Edge e = G[u][i];
			if (d[e.t] == INFTY) {
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

//??¨?????´???????±?????????????
int diamterOfTree()
{
	bfs(0);
	int maxv = 0;
	int tgt = 0;

	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) {
			continue;
		}
		if (maxv < d[i]) {
			maxv = d[i];
			tgt = i;
		}
	}

	//??????????????????????????????????????????????????¢?´¢??§?????¢????±???????
	bfs(tgt);

	maxv = 0;

	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) {
			continue;
		}
		if (maxv < d[i]) {
			maxv = d[i];
		}
	}

	return maxv;

}

void main(void)
{
	int s, t, w;
	cin >> n;


	//n-1?????????????????°????????§???????????????????????????????????\???????????±????????????????????\????????????????????????
	for (int i = 0; i < n - 1; i++) {
		cin >> s >> t >> w;

		G[s].push_back(Edge(t, w));
		G[t].push_back(Edge(s, w));
	}

	cout << diamterOfTree() << endl;

}

Compiler output:
a.cc:86:1: error: '::main' must return 'int'
   86 | void main(void)
      | ^~~~
Language: C++

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

//??¨?????\?????°????????§???
#define MAX 100000 
#define INFTY (1 << 30)

//???????????????
class Edge
{
public :
	int t, w;//???????????£?????????????????????
	Edge(){}
	Edge(int t, int w) :t(t), w(w) {}
};

vector<Edge> G[MAX];
int n, d[MAX];//??¨?????\?????°??????????????¢?´¢???????§??????????????????¢

bool vis[MAX];
int cnt;

void bfs(int s) 
{
	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
	}

	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	int u;

	while (!Q.empty()) {
		u = Q.front();
		Q.pop();

		for (int i = 0; i < G[u].size(); i++) {
			Edge e = G[u][i];
			if (d[e.t] == INFTY) {
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

//??¨?????´???????±?????????????
int diamterOfTree()
{
	bfs(0);
	int maxv = 0;
	int tgt = 0;

	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) {
			continue;
		}
		if (maxv < d[i]) {
			maxv = d[i];
			tgt = i;
		}
	}

	//??????????????????????????????????????????????????¢?´¢??§?????¢????±???????
	bfs(tgt);

	maxv = 0;

	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY) {
			continue;
		}
		if (maxv < d[i]) {
			maxv = d[i];
		}
	}

	return maxv;

}

void main()
{
	int s, t, w;
	cin >> n;


	//n-1?????????????????°????????§???????????????????????????????????\???????????±????????????????????\????????????????????????
	for (int i = 0; i < n - 1; i++) {
		cin >> s >> t >> w;

		G[s].push_back(Edge(t, w));
		G[t].push_back(Edge(s, w));
	}

	cout << diamterOfTree() << endl;

}

Compiler output:
a.cc:86:1: error: '::main' must return 'int'
   86 | void main()
      | ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int n;
const int MAX=100000;
const int INF=123456789;
vector<pair<int,int> > G[MAX];
bool vis[MAX];
int d[MAX];
int maxv;

void bfs(int s){
  for(int i=0;i<n;i++) d[i]=INF;

  queue<int> q;
  q.push(s);
  d[s]=0;
  while(!q.empty()){
    int u=q.front();q.pop();
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i].first;
      if(d[v]==INF){
        d[v]=d[u]+v.second;
        q.push(v);
      }
    }
  }
}

void solve(){
   bfs(0);
   maxv=0;
   int tgt=0;
   for(int i=0;i<n;i++){
     if(d[i]==INF) continue;
     if(maxv<d[i]){
       maxv=d[i];
       tgt=i;
     }
   }

   bfs(tgt);
   maxv=0;
   for(int i=0;i<n;i++){
     if(d[i]==INF) continue;
     maxv=max(maxv,d[i]);
   }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    int s,t,w;
    cin>>s>>t>>w;
    G[s].push_back(make_pair(t,w));
  }

  solve();

  cout<<maxv<<endl;
  return 0;
}

Compiler output:
a.cc: In function 'void bfs(int)':
a.cc:22:21: error: request for member 'second' in 'v', which is of non-class type 'int'
   22 |         d[v]=d[u]+v.second;
      |                     ^~~~~~
Language: C++

#include<iostream>
#include<vector>
#include<queue>

#define rep(i,n) for(int i = 0; i < n; ++i)
#define X first
#define Y second
#define all(x) x.begin(), x.end()
using namespace std;
using PII=pair<int,int>;

// Tree
class Node{
  public:
    int dist;
    int parent;
    vector<PII> children;
    Node(){dist=0;};
};

int main(void){
  int a, b, c, n;
  Node nodes[200000];
  vector<int> d;

  cin >> n;
  d.resize(n+1, 0);

  rep(i,n-1){
    cin >> a >> b >> c;
    if(a>b) swap(a,b);
    nodes[a].children.push_back(PII(b,c));
    nodes[b].parent = a;
  }

  queue<int> q;
  q.push(0);

  while(!q.empty()){
    int index = q.front();q.pop();
    rep(i,nodes[index].children.size()){
      PII e = nodes[index].children[i];
      q.push(e.X);
      nodes[e.X].dist = nodes[index].dist + e.Y;
    }
  }

//   rep(i,n){
//     cout << "i: " << i << "  dist: " << nodes[i].dist << endl;
//   }

  rep(i,nodes[0].children.size()){
    PII chi = nodes[0].children[i];
    q.push(chi.X);
    while(!q.empty()){
      int index = q.front();q.pop();
      //cout << "index: " << index << endl;
      d[i] = max(d[i], nodes[index].dist);

      rep(j,nodes[index].children.size()){
        PII e = nodes[index].children[j];
        q.push(e.X);
      }
    }
  }

  sort(all(d));
  reverse(all(d));
//   rep(i,d.size()){
//     cout << d[i] << ", ";
//   }
//   cout << endl;


  cout << d[0] + d[1] << endl;

  

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:67:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   67 |   sort(all(d));
      |   ^~~~
      |   short
a.cc:68:3: error: 'reverse' was not declared in this scope
   68 |   reverse(all(d));
      |   ^~~~~~~
Language: C++

#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define INFTY (1 << 30)

class Edge {
	public:
	    int t, w;
	    Edge() {}
	    Edge(int t, int w) : t(t), w(w) {}
}

vector<Edge> G[MAX];
int n, d[MAX];
bool vis[MAX];
int cnt;

void bfs(int s) {
	for(int i = 0; i < n; i++) d[i] = INFTY;
	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	int u;
	while(!Q.empty()) {
		u = Q.front();
		Q.pop();
		for(int i = 0; i < G[u].size(); i++) {
			Edge e = G[u][i];
			if(d[e.t] == INFTY) {
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

 
void solve() {
	bfs(0);
	int maxv = 0, tgt = 0;
	for(int i = 0; i < n; i++) {
		if(d[i] == INFTY) continue;
		if(maxv < d[i]) {
			maxv = d[i];
			tgt = i;
		}  
	}
	
	bfs(tgt);
	maxv = 0;
	for(int i = 0; i < n; i++) {
		if(d[i] == INFTY) continue;
		if(maxv < d[i]) {
			maxv = d[i];
		}
	}
	
	cout << maxv << endl;
}

main() {
	int s, t, w;
	cin >> n;
	
	for(int i = 0; i < n - 1; i++) {
		cin >> s >> t >> w;
		
		G[s].push_back(Edge(t, w));
		G[t].push_back(Edge(s, w)); 
	}
	
	solve();
}

Compiler output:
a.cc:15:14: error: invalid declarator before 'G'
   15 | vector<Edge> G[MAX];
      |              ^
a.cc: In function 'void bfs(int)':
a.cc:29:36: error: 'G' was not declared in this scope
   29 |                 for(int i = 0; i < G[u].size(); i++) {
      |                                    ^
a.cc: At global scope:
a.cc:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main() {
      | ^~~~
a.cc: In function 'int main()':
a.cc:70:17: error: 'G' was not declared in this scope
   70 |                 G[s].push_back(Edge(t, w));
      |                 ^
Language: C++

#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define INFTY (1 << 30)

class Edge {
	public:
	    int t, w;
	    Edge() {}
	    Edge(int t, int w) {
		    this.t = t;
		    this.w = w;
			 
		}
};

vector<Edge> G[MAX];
int n, d[MAX];
bool vis[MAX];
int cnt;

void bfs(int s) {
	for(int i = 0; i < n; i++) d[i] = INFTY;
	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	int u;
	while(!Q.empty()) {
		u = Q.front();
		Q.pop();
		for(int i = 0; i < G[u].size(); i++) {
			Edge e = G[u][i];
			if(d[e.t] == INFTY) {
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

 
void solve() {
	bfs(0);
	int maxv = 0, tgt = 0;
	for(int i = 0; i < n; i++) {
		if(d[i] == INFTY) continue;
		if(maxv < d[i]) {
			maxv = d[i];
			tgt = i;
		}  
	}
	
	bfs(tgt);
	maxv = 0;
	for(int i = 0; i < n; i++) {
		if(d[i] == INFTY) continue;
		if(maxv < d[i]) {
			maxv = d[i];
		}
	}
	
	cout << maxv << endl;
}

main() {
	int s, t, w;
	cin >> n;
	
	for(int i = 0; i < n - 1; i++) {
		cin >> s >> t >> w;
		
		G[s].push_back(Edge(t, w));
		G[t].push_back(Edge(s, w)); 
	}
	
	solve();
}

Compiler output:
a.cc: In constructor 'Edge::Edge(int, int)':
a.cc:13:26: error: request for member 't' in '(Edge*)this', which is of pointer type 'Edge*' (maybe you meant to use '->' ?)
   13 |                     this.t = t;
      |                          ^
a.cc:14:26: error: request for member 'w' in '(Edge*)this', which is of pointer type 'Edge*' (maybe you meant to use '->' ?)
   14 |                     this.w = w;
      |                          ^
a.cc: At global scope:
a.cc:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main() {
      | ^~~~
Language: C++

#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;

const int V_MAX = 100000;

struct Edge {
	int n;
	int w;
};

int solve(vector<Edge> graph[],int v,int prev, int n,int& m) {

	int first = 0;
	int second = 0;

	for (int i = 0; i < graph[v].size(); i++) {
		if (graph[v][i].n == prev)continue;
		int res = solve(graph, graph[v][i].n, v, graph[v][i].w + n);

		if (res > second) {
			if (res > first) {
				second = first;
				first = res;
			}
			else {
				second = res;
			}
		}
	}

	m = max(m, first + max(second, n));

	return first;
}

int main() {
	int n;
	vector<Edge> graph[V_MAX];

	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int s, t, w;
		Edge e1, e2;
		scanf("%d%d%d", &s, &t, &w);
		
		e1.n = t; e1.w = w;
		e2.n = s; e2.w = w;

		graph[s].push_back(e1);
		graph[t].push_back(e2);
	}

	int m = 0;
	solve(graph, 0,0, 0,m);

	printf("%d\n", m);

	return 0;
}

Compiler output:
a.cc: In function 'int solve(std::vector<Edge>*, int, int, int, int&)':
a.cc:20:32: error: too few arguments to function 'int solve(std::vector<Edge>*, int, int, int, int&)'
   20 |                 int res = solve(graph, graph[v][i].n, v, graph[v][i].w + n);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:13:5: note: declared here
   13 | int solve(vector<Edge> graph[],int v,int prev, int n,int& m) {
      |     ^~~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

struct edge
{
  int to, cost;
};

vector< edge > g[100000];
long long dist[100000];


void dfs1(int idx, int par)
{
  for(edge &e : g[idx]) {
    if(e.to == par) continue;
    dfs1(e.to, idx);
    dist[idx] = max(dist[idx], dist[e.to] + e.cost);
  }
}

int dfs2(int idx, int d_par, int par)
{
  vector< pair< int, int > > d_child;
  // d_child.emplace_back(0, -1); 
  for(edge &e : g[idx]) {
    if(e.to == par) d_child.emplace_back(d_par + e.cost, e.to);
    else d_child.emplace_back(e.cost + dist[e.to], e.to);
  }
  sort(d_child.rbegin(), d_child.rend());
  int ret = d_child[0].first + d_child[1].first;
  for(edge &e : g[idx]) {
    if(e.to == par) continue;
    ret = max(ret, dfs2(e.to, d_child[d_child[0].second == e.to].first, idx));
  }
  return (ret);
}

int main()
{
  int N;
  cin >> N;
  for(int i = 0; i < N - 1; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    g[a].push_back((edge) {b, w});
    g[b].push_back((edge) {a, w});
  }

  if(N == 1) {
    cout << 0 << endl;
  } else if(N == 2) {
    cout << g[0][0].cost << endl;
  } else {
    int root = 0;
    for(int i = 0; i < N; i++) if(g[i].size()) >= 2) root = i;
    dfs1(root, -1);
    cout << dfs2(root, 1333, 1333) << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:57:48: error: expected primary-expression before '>=' token
   57 |     for(int i = 0; i < N; i++) if(g[i].size()) >= 2) root = i;
      |                                                ^~