1 #include<bits/stdc++.h>
2 using namespace std;
3 #define R register int
4 #define rep(i,a,b) for(R i=a;i<=b;i++)
5 #define Rep(i,a,b) for(R i=a;i>=b;i--)
6 #define rp(i,x) for(R i=H[x];i!=-1;i=E[i].nt)
7 #define ms(i,a) memset(a,i,sizeof(a))
8 #define gc() getchar()
9 #define LL long long
10 template<class T>void read(T &x){
11 x=0; char c=0;
12 while (!isdigit(c)) c=gc();
13 while (isdigit(c)) x=x*10+(c^48),c=gc();
14 }
15 int const N=20000+3;
16 struct Edge{
17 int to,nt,w;
18 }E[N<<1];
19 int n,H[N],cnt,vis[N],ans,sz[N];
20 void add(int a,int b,int c){
21 E[cnt]=(Edge){b,H[a],c}; H[a]=cnt++;
22 }
23 int getsize(int x,int fa){
24 sz[x]=1;
25 rp(i,x){
26 int v=E[i].to;
27 if(v==fa || vis[v]) continue;
28 sz[x]+=getsize(v,x);
29 }
30 return sz[x];
31 }
32 int findroot(int x,int fa,int sum){
33 int num=0,tot=1;
34 rp(i,x){
35 int v=E[i].to;
36 if(v==fa || vis[v]) continue;
37 int t=findroot(v,x,sum);
38 if(t) return t;
39 num=max(num,sz[v]);
40 tot+=sz[v];
41 }
42 num=max(num,sum-tot);
43 if(num*2<=sum) return x;
44 else return 0;
45 }
46 void dfs(int x,int fa,int d,int *tmp){
47 tmp[d]++;
48 rp(i,x){
49 int v=E[i].to;
50 if(v==fa || vis[v]) continue;
51 dfs(v,x,(d+E[i].w)%3,tmp);
52 }
53 }
54 void solve(int x){
55 int num[3];ms(0,num);
56 rp(i,x){
57 int v=E[i].to;
58 if(vis[v]) continue;
59 int z=findroot(v,0,getsize(v,0));
60 int tmp[3];ms(0,tmp);
61 dfs(v,0,E[i].w%3,tmp);
62 ans+=2*tmp[0];
63 rep(j,0,2) ans+=2*num[(3-j)%3]*tmp[j];
64 rep(j,0,2) num[j]+=tmp[j];
65 vis[z]=1;
66 solve(z);
67 }
68 ans++;
69 }
70 int gcd(int x,int y){return y? gcd(y,x%y): x;}
71 int main(){
72 read(n); ms(-1,H);
73 rep(i,1,n-1){
74 int x,y,z; read(x); read(y); read(z);
75 add(x,y,z); add(y,x,z);
76 }
77 int z=findroot(1,0,getsize(1,0));
78 vis[z]=1;
79 solve(z);
80 int g=gcd(ans,n*n);
81 printf("%d/%d\n",ans/g,n*n/g);
82 return 0;
83 }