#include<bits/stdc++.h> #define MAX_N 200000 usingnamespace std; int n, rt, tot, ans; vector <int> G[MAX_N+5], E[MAX_N+5]; int s[MAX_N+5], h[MAX_N+5], dep[MAX_N+5], cnt[3]; bool mrk[MAX_N+5]; voidaddedge(int u, int v, int c){G[u].push_back(v), E[u].push_back(c%3);} intgcd(int a, int b){return b ? gcd(b, a%b) : a;} intfrac(int a, int b){return a/gcd(a, b);} voidgetrt(int u, int fa){ s[u] = 1, h[u] = 0; for (int i = 0; i < (int)G[u].size(); i++) { int v = G[u][i]; if (v == fa || mrk[v]) continue; getrt(v, u); s[u] += s[v], h[u] = max(h[u], s[v]); } h[u] = max(h[u], tot-s[u]); if (h[u] < h[rt]) rt = u; } voidgetdep(int u, int fa){ cnt[dep[u]]++; for (int i = 0; i < (int)G[u].size(); i++) { int v = G[u][i], c = E[u][i]; if (v == fa || mrk[v]) continue; dep[v] = (dep[u]+c)%3, getdep(v, u); } } intcalc(int u, int init){ cnt[0] = cnt[1] = cnt[2] = 0; dep[u] = init, getdep(u, 0); return cnt[0]*cnt[0]+cnt[1]*cnt[2]*2; } voidDFS(int u){ ans += calc(u, 0), mrk[u] = true; for (int i = 0; i < (int)G[u].size(); i++) { int v = G[u][i], c = E[u][i]; if (mrk[v]) continue; ans -= calc(v, c), rt = 0, tot = s[v], getrt(v, 0), DFS(rt); } } intmain(){ scanf("%d", &n); for (int i = 1, u, v, c; i < n; i++) scanf("%d%d%d", &u, &v, &c), addedge(u, v, c), addedge(v, u, c); tot = h[0] = n, getrt(1, 0), DFS(rt); printf("%d/%d", frac(ans, n*n), frac(n*n, ans)); return0; }