Language: C++


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

using namespace std;

static const int MAX = 100000;
static const int INFTY = (1 << 30);

class Edte {
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 = 0l
  int rgt = 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;
    }
    maxv = max(maxv, d[i]);
  }

  cout << maxv << endl;
}

int 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();

  return 0;
}



Compiler output:
a.cc:14:3: error: ISO C++ forbids declaration of 'Edge' with no type [-fpermissive]
   14 |   Edge() {}
      |   ^~~~
a.cc:15:3: error: ISO C++ forbids declaration of 'Edge' with no type [-fpermissive]
   15 |   Edge(int t, int w)
      |   ^~~~
a.cc: In member function 'int Edte::Edge()':
a.cc:14:11: warning: no return statement in function returning non-void [-Wreturn-type]
   14 |   Edge() {}
      |           ^
a.cc: In member function 'int Edte::Edge(int, int)':
a.cc:16:7: error: only constructors take member initializers
   16 |     : t(t),
      |       ^
a.cc:17:5: error: expected identifier before ',' token
   17 |     , w(w) {}
      |     ^
a.cc:17:13: warning: no return statement in function returning non-void [-Wreturn-type]
   17 |     , w(w) {}
      |             ^
a.cc: At global scope:
a.cc:20:14: error: expected initializer before 'G'
   20 | vector(Edge) G[MAX];
      |              ^
a.cc: In function 'void bfs(int)':
a.cc:36:25: error: 'G' was not declared in this scope
   36 |     for (int i = 0; i < G[u].size(); i++) {
      |                         ^
a.cc:37:7: error: 'Edge' was not declared in this scope; did you mean 'Edte'?
   37 |       Edge e = G[u][i];
      |       ^~~~
      |       Edte
a.cc:38:13: error: 'e' was not declared in this scope
   38 |       if (d[e.t] == INFTY) {
      |             ^
a.cc: In function 'void solve()':
a.cc:49:3: error: expected ',' or ';' before 'int'
   49 |   int rgt = 0;
      |   ^~~
a.cc:56:7: error: 'tgt' was not declared in this scope
   56 |       tgt = i;
      |       ^~~
a.cc:60:7: error: 'tgt' was not declared in this scope
   60 |   bfs(tgt);
      |       ^~~
a.cc: In function 'int main()':
a.cc:79:5: error: 'G' was not declared in this scope
   79 |     G[s].push_back(Edge(t, w));
      |     ^
a.cc:79:20: error: 'Edge' was not declared in this scope; did you mean 'Edte'?
   79 |     G[s].push_back(Edge(t, w));
      |                    ^~~~
      |                    Edte