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

Puzzled Elena

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2508    Accepted Submission(s): 888


Problem Description
Since both Stefan and Damon fell in love with Elena, and it was really difficult for her to choose. Bonnie, her best friend, suggested her to throw a question to them, and she would choose the one who can solve it.

Suppose there is a tree with n vertices and n - 1 edges, and there is a value at each vertex. The root is vertex 1. Then for each vertex, could you tell me how many vertices of its subtree can be said to be co-prime with itself?
NOTES: Two vertices are said to be co-prime if their values' GCD (greatest common divisor) equals 1.
 

Input
There are multiply tests (no more than 8).
For each test, the first line has a number $n$ $(1 \leq n \leq 10^5)$, after that has $n-1$ lines, each line has two numbers a and b $(1 \leq a,b \leq n)$, representing that vertex a is connect with vertex b. Then the next line has n numbers, the $i^{th}$ number indicates the value of the $i^{th}$ vertex. Values of vertices are not less than 1 and not more than $10^5$.
 

Output
For each test, at first, please output "Case #k: ", k is the number of test. Then, please output one line with n numbers (separated by spaces), representing the answer of each vertex.
 

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

Sample Output
Case #1: 1 1 0 0 0
 

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-11-22 09:35:06, Gzip enabled