8-Laboratoriya ishi Mavzu: Kenglik bo’yicha izlash algoritmi(bfs)



Yüklə 0,57 Mb.
səhifə5/5
tarix08.06.2022
ölçüsü0,57 Mb.
#60964
1   2   3   4   5
8-tajriba. Algoritm loyihalash

input

output

3
2 0
3 0
0

010


7-topshiriq
— Arny! What happened with coordinator?
Bad working coordinator was the everlasting trouble of their spaceship. Arny already had been working under this trouble while his not very attentive and responsible mate just noticed the breakage. Judging by schematics the broken module of coordinator consists of the set of special gears connected with each other in order to transfer the traction from the kinetic generator to the lot of antenna driving engines.
Despite the extraterrestrial origin of these gears, they are connected by usual terrestrial method: the cogs of one gear-wheel get into the slots between cogs of another gear-wheel. So the rotation of the first gear-wheel is transmitted to the second gear-wheel.
After the multiple Arny’s revisions, no unnecessary gears stayed in the coordinator. It means that there is no cycles in gears connection graph. The only problem now is to check that all the gears have right directions and speeds of rotation.

Input


First line of input contains the number of gear-wheels in mechanism N (1 ≤ N ≤ 1000). The next N lines contain the information about the gear-wheels. i-th line contains K (1 ≤ K ≤ 1000) — the number of cogs on the i-th gear-wheel followed by the list of gears, that are connected to the i-th one. Zero ends the list.
The last line of input contains the number of gear-wheel, that is connected to the kinetic-generator and the speed of its rotation V (1 ≤ V ≤ 1000). This gear-wheel rotates in counter-clockwise direction.

Output


Output should contain N lines. In the i-th line there is a speed of rotation of i-th gear-wheel in the form of irreducible fraction. Numerator and denominator of this fraction should be separated by the sign ‘/’. If speed is negative, it is assumed that the gear-wheel rotates in clockwise direction (in this case the minus sign should be displayed before numerator). Otherwise the gear-wheel rotates in counter-clockwise direction. If speed equals zero than numerator should be equal 0 and denominator should be equal to 1. It is guaranteed that neither numerator nor denominator of all speeds will be greater than 106.

Sample


input

output

4
10 2 3 0
20 1 0
40 1 4 0
100 3 0
1 6

6/1
-3/1
-3/2
3/5




Yüklə 0,57 Mb.

Dostları ilə paylaş:
1   2   3   4   5




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin