Revizia anterioară Revizia următoare
Fişierul intrare/ieşire: | sumtree.in, sumtree.out | Sursă | IIOT 2022-23 Runda I |
Autor | Vlad-Mihai Bogdan | Adăugată de | |
Timp execuţie pe test | 0.75 sec | Limită de memorie | 262144 kbytes |
Scorul tău | N/A | Dificultate | N/A |
Vezi solutiile trimise | Statistici
Sumtree
You are given a tree with N nodes. Each node has values assigned to it, . You must calculate the sum cost of every pair nodes (u, v), where
and u ≠ v. For a pair of nodes [Unparseable or potentially dangerous LaTeX formula! Error 2 : def] (1 ≤
≤ 30000). Each of the next N - 1 lines will contain a pair of nodes (u, v), each representing an edge of the tree.
For tests worth 20 points (1 ≤ N ≤ 1000)
For tests worth 20 more points, for i = 1, 2,...n
Date de ieşire
The output will contain the sum of costs over all pairs of nodes (u, v), such that gcd(value[u], value[v]) > 1
Exemplu
sumtree.in | sumtree.out |
---|---|
5 2 7 14 22 77 1 2 1 3 2 4 4 5 | 442 |