|
|
|
@ -2,29 +2,30 @@
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#define rg register
|
|
|
|
|
#define go(i, a, b) for (rg int i = a; i <= b; i++)
|
|
|
|
|
#define mem(a, b) memset(a, b, sizeof(a))
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 2e5 + 2;
|
|
|
|
|
const int N = 2e5 + 10;
|
|
|
|
|
int T, n, du[N];
|
|
|
|
|
|
|
|
|
|
struct node {
|
|
|
|
|
int to, w;
|
|
|
|
|
};
|
|
|
|
|
vector<node> c[N];
|
|
|
|
|
|
|
|
|
|
bool v[N];
|
|
|
|
|
int d[N], f[N];
|
|
|
|
|
|
|
|
|
|
void clean() {
|
|
|
|
|
mem(v, 0);
|
|
|
|
|
mem(du, 0);
|
|
|
|
|
mem(d, 0);
|
|
|
|
|
mem(f, 0);
|
|
|
|
|
go(i, 1, n) c[i].clear();
|
|
|
|
|
memset(v, 0, sizeof v);
|
|
|
|
|
memset(du, 0, sizeof du);
|
|
|
|
|
memset(d, 0, sizeof d);
|
|
|
|
|
memset(f, 0, sizeof f);
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= n; i++) c[i].clear();
|
|
|
|
|
}
|
|
|
|
|
void dp(int x) {
|
|
|
|
|
v[x] = 1;
|
|
|
|
|
int size = c[x].size() - 1;
|
|
|
|
|
go(i, 0, size) {
|
|
|
|
|
for (int i = 0; i <= size; i++) {
|
|
|
|
|
int to = c[x][i].to, w = c[x][i].w;
|
|
|
|
|
if (v[to]) continue;
|
|
|
|
|
dp(to);
|
|
|
|
@ -38,7 +39,7 @@ void dp(int x) {
|
|
|
|
|
void dfs(int x) {
|
|
|
|
|
v[x] = 1;
|
|
|
|
|
int size = c[x].size() - 1;
|
|
|
|
|
go(i, 0, size) {
|
|
|
|
|
for (int i = 0; i <= size; i++) {
|
|
|
|
|
int to = c[x][i].to, w = c[x][i].w;
|
|
|
|
|
if (v[to]) continue;
|
|
|
|
|
if (du[x] == 1)
|
|
|
|
@ -51,13 +52,13 @@ void dfs(int x) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
scanf("%d", &T);
|
|
|
|
|
cin >> T;
|
|
|
|
|
while (T--) {
|
|
|
|
|
scanf("%d", &n);
|
|
|
|
|
cin >> n;
|
|
|
|
|
clean();
|
|
|
|
|
int x, y, z;
|
|
|
|
|
go(i, 1, n - 1) {
|
|
|
|
|
scanf("%d%d%d", &x, &y, &z);
|
|
|
|
|
for (int i = 1; i < n; i++) {
|
|
|
|
|
cin >> x >> y >> z;
|
|
|
|
|
c[x].push_back((node){y, z});
|
|
|
|
|
c[y].push_back((node){x, z});
|
|
|
|
|
du[x]++;
|
|
|
|
@ -65,10 +66,10 @@ int main() {
|
|
|
|
|
}
|
|
|
|
|
dp(1);
|
|
|
|
|
f[1] = d[1];
|
|
|
|
|
mem(v, 0);
|
|
|
|
|
memset(v, 0, sizeof v);
|
|
|
|
|
dfs(1);
|
|
|
|
|
int ans = 0;
|
|
|
|
|
go(i, 1, n) ans = max(ans, f[i]);
|
|
|
|
|
for (int i = 1; i <= n; i++) ans = max(ans, f[i]);
|
|
|
|
|
printf("%d\n", ans);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|