이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
class Bridges:
def __init__(self, n, m):
self.n = n
self.m = m
self.graph = [[] for _ in range(n+1)]
self.weights = {}
def add_bridge(self, u, v, w):
self.graph[u].append(v)
self.graph[v].append(u)
self.weights[(u, v)] = w
self.weights[(v, u)] = w
def update_weight(self, bridge_id, new_weight):
edges = list(self.weights.keys())
if bridge_id <= len(edges):
u, v = edges[bridge_id - 1]
self.weights[(u, v)] = new_weight
self.weights[(v, u)] = new_weight
def reachable_islands(self, s):
visited = [False] * (self.n + 1)
self.dfs(s, visited)
return visited.count(True)
def dfs(self, node, visited):
visited[node] = True
for neighbor in self.graph[node]:
if not visited[neighbor]:
self.dfs(neighbor, visited)
n, m = map(int, input().split())
bridges = Bridges(n, m)
for _ in range(m):
u, v, w = map(int, input().split())
bridges.add_bridge(u, v, w)
q = int(input())
for _ in range(q):
query = list(map(int, input().split()))
if query[0] == 1:
_, bridge_id, new_weight = query
bridges.update_weight(bridge_id, new_weight)
elif query[0] == 2:
_, s, t = query
result = bridges.reachable_islands(s)
print(result)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |