Language: C++

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#ifdef _MSC_VER
int getchar_unlocked() { return getchar(); }
#endif
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << endl;
#define qp(f) [](auto i){return f;}
using LL=long long;
using VI=vector<int>;
using VL=vector<LL>;
using VS=vector<string>;
using VVI=vector<vector<int>>;
using PII=pair<int, int>;

/* INPUT */
struct inputter_Str {
	vector<string> inputbuffer;
	string operator [](int n) {
		while (inputbuffer.size() <= n) {
			string s; char c = getchar_unlocked();
			while (c != '\0' && c != '\n' && c != '\t' && c != ' ') {
				s.push_back(c); c = getchar_unlocked();
			}
			inputbuffer.push_back(s);
		}
		return inputbuffer[n];
	}
	operator string() {
		string s; char c = getchar_unlocked();
		while (c != '\0' && c != '\n' && c != '\t' && c != ' ') {
			s.push_back(c); c = getchar_unlocked();
		}
		inputbuffer.push_back(s);
		return s;
	}
}in;
struct inputter_Int {
	int operator [](int n) { return stoi(in[n]); }
	operator int() { return stoi(string(in)); }
}ini;
struct inputter_LL {
	LL operator [](int n) { return stoll(in[n]); }
	operator LL() { return stoll(string(in)); }
}inl;
struct inputter_Double {
	double operator [](int n) { return stod(in[n]); }
	operator double() { return stold(string(in)); }
}ind;
vector<int> invi(int n, int m) { vector<int> v(m); for (int i = 0; i < m; ++i)v[i] = ini[n + i]; return v; }
vector<LL> invl(int n, int m) { vector<LL> v(m); for (int i = 0; i < m; ++i)v[i] = inl[n + i]; return v; }
vector<string> invs(int n, int m) { vector<string> v(m); for (int i = 0; i < m; ++i)v[i] = in[n + i]; return v; }
int Suminvi(int n, int m) { return Sum(invi(n, m), 0); }LL Suminvl(int n, int m) { return Sum(invl(n, m), 0LL); }
int Maxinvi(int n, int m) { return Max(invi(n, m)); }   LL Maxinvl(int n, int m) { return Max(invl(n, m)); }
int Mininvi(int n, int m) { return Min(invi(n, m)); }   LL Mininvl(int n, int m) { return Min(invl(n, m)); }
struct inputter_Int_Fast {
	int get() {
		int num = 0; bool neg = false; char c = getchar_unlocked();
		if (c == '-') { neg = true; c = getchar_unlocked(); }
		while ('0' <= c && c <= '57') { num = num * 10 + (c - '0'); c = getchar_unlocked(); }
		return neg ? -num : num;
	}
	operator int() { return get(); }
}inif;
struct inputter_LL_Fast {
	LL get() {
		LL num = 0; bool neg = false; char c = getchar_unlocked();
		if (c == '-') { neg = true; c = getchar_unlocked(); }
		while ('0' <= c && c <= '57') { num = num * 10LL + LL(c - '0'); c = getchar_unlocked(); }
		return neg ? -num : num;
	}
	operator LL() { return get(); }
}inlf;
vector<int> invif(int n) {
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		int num = 0; bool neg = false; char c = getchar_unlocked();
		if (c == '-') { neg = true; c = getchar_unlocked(); }
		while ('0' <= c && c <= '57') { num = num * 10 + (c - '0'); c = getchar_unlocked(); }
		v[i] = neg ? -num : num;
	}
	return v;
}
vector<LL> invlf(int n) {
	vector<LL> v(n);
	for (int i = 0; i < n; ++i) {
		LL num = 0; bool neg = false; char c = getchar_unlocked();
		if (c == '-') { neg = true; c = getchar_unlocked(); }
		while ('0' <= c && c <= '57') { num = num * 10LL + LL(c - '0'); c = getchar_unlocked(); }
		v[i] = neg ? -num : num;
	}
	return v;
}

ostream& operator << (ostream& ostr, inputter_Str i) { ostr << string(i); return ostr; }


struct edge {
	LL to, cost;
};

int n;
vector<vector<edge>> g;

void dfs(LL v, LL p, LL deep, VL& dist) {
	dist[v] = deep;
	for (auto e : g[v]) {
		if (e.to == p)continue;
		dfs(e.to, v, deep + e.cost, dist);
	}
}


int main() {
	n = inlf;
	g.resize(n);

	rep(i, n - 1) {
		LL s = inlf, t = inlf, w = inlf;
		g[s].pb({ t,w });
		g[t].pb({ s,w });
	}

	rep(i, n) {
		VL d(n);
		dfs(i, -1, 0, d);
		printf("%lld\n",Max(d));
	}
}


Compiler output:
a.cc:66:41: warning: multi-character character constant [-Wmultichar]
   66 |                 while ('0' <= c && c <= '57') { num = num * 10 + (c - '0'); c = getchar_unlocked(); }
      |                                         ^~~~
a.cc:75:41: warning: multi-character character constant [-Wmultichar]
   75 |                 while ('0' <= c && c <= '57') { num = num * 10LL + LL(c - '0'); c = getchar_unlocked(); }
      |                                         ^~~~
a.cc:85:41: warning: multi-character character constant [-Wmultichar]
   85 |                 while ('0' <= c && c <= '57') { num = num * 10 + (c - '0'); c = getchar_unlocked(); }
      |                                         ^~~~
a.cc:95:41: warning: multi-character character constant [-Wmultichar]
   95 |                 while ('0' <= c && c <= '57') { num = num * 10LL + LL(c - '0'); c = getchar_unlocked(); }
      |                                         ^~~~
a.cc: In function 'int Suminvi(int, int)':
a.cc:59:36: error: 'Sum' was not declared in this scope
   59 | int Suminvi(int n, int m) { return Sum(invi(n, m), 0); }LL Suminvl(int n, int m) { return Sum(invl(n, m), 0LL); }
      |                                    ^~~
a.cc: In function 'LL Suminvl(int, int)':
a.cc:59:91: error: 'Sum' was not declared in this scope
   59 | int Suminvi(int n, int m) { return Sum(invi(n, m), 0); }LL Suminvl(int n, int m) { return Sum(invl(n, m), 0LL); }
      |                                                                                           ^~~
a.cc: In function 'int Maxinvi(int, int)':
a.cc:60:36: error: 'Max' was not declared in this scope
   60 | int Maxinvi(int n, int m) { return Max(invi(n, m)); }   LL Maxinvl(int n, int m) { return Max(invl(n, m)); }
      |                                    ^~~
a.cc: In function 'LL Maxinvl(int, int)':
a.cc:60:91: error: 'Max' was not declared in this scope
   60 | int Maxinvi(int n, int m) { return Max(invi(n, m)); }   LL Maxinvl(int n, int m) { return Max(invl(n, m)); }
      |                                                                                           ^~~
a.cc: In function 'int Mininvi(int, int)':
a.cc:61:36: error: 'Min' was not declared in this scope; did you mean 'sin'?
   61 | int Mininvi(int n, int m) { return Min(invi(n, m)); }   LL Mininvl(int n, int m) { return Min(invl(n, m)); }
      |                                    ^~~
      |                                    sin
a.cc: In function 'LL Mininvl(int, int)':
a.cc:61:91: error: 'Min' was not declared in this scope; did you mean 'sin'?
   61 | int Mininvi(int n, int m) { return Min(invi(n, m)); }   LL Mininvl(int n, int m) { return Min(invl(n, m)); }
      |                                                                                           ^~~
      |                                                                                           sin
a.cc: In function 'int main()':
a.cc:133:33: error: 'Max' was not declared in this scope
  133 |                 printf("%lld\n",Max(d));
      |                                 ^~~