Español
Abrir en Telegram

Publicaciónimport math

29 de junio de 2025
D
Deloitte | COGNIZANT | IBM | CAPGEMINI
import math from collections import defaultdict, deque def is_perfect_square(x): root = int(math.isqrt(x)) return root * root == x def solve(n, val, edge): tree = defaultdict(list) for u, v in edge: tree[u].append(v) tree[v].append(u) parent = [-1] * n path = [[] for _ in range(n)] queue = deque([0]) visited = [False] * n visited[0] = True while queue: node = queue.popleft() for neighbor in tree[node]: if not visited[neighbor]: visited[neighbor] = True parent[neighbor] = node path[neighbor] = path[node] + [node] queue.append(neighbor) total_sum = 0 for i in range(1, n): vi = 0 for anc in path[i]: if is_perfect_square(val[i] * val[anc]): vi += 1 total_sum += vi return total_sum n=int(input()) val=[int(i) for i in input().split()] edge=[[int(i) for i in input().split()] for _ in range(n-1)] print(solve(n,val,edge)) Tree Climber✅✅
929 ·

Cerca en el feed

DDeloitte | COGNIZANT | IBM | CAPGEMINITrilogy✅✅ q3DDeloitte | COGNIZANT | IBM | CAPGEMINIHackwithinfy mockTest✅
este mensaje
DDeloitte | COGNIZANT | IBM | CAPGEMINIMeesho✅ Contact : @MLCODER2DDeloitte | COGNIZANT | IBM | CAPGEMINIMeesho✅ Contact : @MLCODER2
DDeloitte | COGNIZANT | IBM | CAPGEMINIDeloitte | COGNIZANT | IBM | CAPGEMINI@python_java_Coding · canal · Tecnología
7 178suscriptores451alcance medio por publicación
Feed de la comunidad Abrir en Telegram

Un feed público abierto del índice de búsqueda ChatCrawler — el “Google del Telegram público”; se actualiza a medida que se rastrea la comunidad. Las horas se muestran en UTC.

Solo contenido público, API oficial de Telegram. Acerca de · Preguntas frecuentes · Límites del índice · Eliminar una página · Catálogo · Búsqueda · Cómo contamos