Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- class Edge:
- def __init__(self, destination, distance):
- self.destination = destination
- self.distance = distance
- def bfs(graph, start_node, damage, total_damage):
- queue = deque([(start_node, damage)])
- visited = set([start_node])
- while queue:
- current_node, current_damage = queue.popleft()
- # Update the total damage for the current node
- total_damage[current_node] += current_damage
- for edge in graph[current_node]:
- neighbor = edge.destination
- if neighbor not in visited:
- new_damage = current_damage // 2
- queue.append((neighbor, new_damage))
- visited.add(neighbor)
- nodes = int(input())
- edges = int(input())
- strikes = int(input())
- graph = [[] for _ in range(nodes)]
- for i in range(edges):
- source, destination, distance = map(int, input().split())
- graph[source].append(Edge(destination, distance))
- graph[destination].append(Edge(source, distance)) # Add for both nodes since it's an undirected graph
- total_damage = [0] * nodes
- visited = set()
- for _ in range(strikes):
- start_node, damage = map(int, input().split())
- if start_node not in visited:
- bfs(graph, start_node, damage, total_damage)
- highest_damage = max(total_damage)
- print(highest_damage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement