F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Tom and game

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 168    Accepted Submission(s): 59


Problem Description
Tom love to play games with Tony.

They think a orderly tetrad (t,i,j,k) is valid, when it satisfy,

1. $1\leq i,j,k\leq t$

2. Exist a positive integer s, which can divide both i and j, and is not smaller than k.

They prepare some tetrads, take turns to operate. When one can't operate, he loses. A valid operate is,

1. Choose a tetrad.

2. Change it to another valid tetrad which is smaller than it on dictionary order.

When compare two tetrads, compare the first element. If equal, compare the second element, and so on.

They think that prepare tetrads every time they want to play is troublesome. So they paint a tree, there is a tetrad on each point. When they want to play, Tom random choose a point P, Tony random choose a point Q. Then they copy down tetrads on points which are on the route connect P and Q (include P and Q), start the game.

Tom always operate first, he wants to know the probability of he wins.
 

Input
Multi test cases(about 8). For each case, the first line contains a positive integer n, indicates the number of points in the tree. In the next n-1 lines, each line contains two integers i and j, indicates there is an edge connect point i and point j. In the next n lines, the i-th line contains four integers, a¡¢b¡¢c¡¢d, indicates the orderly tetrad on point i is (a,b,c,d).

$1\leq n\leq 10000;1\leq i,j\leq n;1\leq a,b,c,d\leq 10000$

It's assured that the tetrad on each point is valid.
 

Output
For each case, output a fraction "x/y", indicates the probability of Tom wins, x and y should be co-prime. If Tom is bound to fail, output "0/1".
 

Sample Input
2 1 2 1 1 1 1 2 1 2 1 5 1 2 2 3 3 4 4 5 1 1 1 1 2 1 1 1 2 1 2 1 2 2 1 1 1 1 1 1
 

Sample Output
3/4 3/5
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-11 18:15:53, Gzip enabled