3887. Incremental Even-Weighted Cycle Queries
You are given a positive integer
n.There is an undirected graph with
nnodes labeled from 0 ton - 1. Initially, the graph has no edges.You are also given a 2D integer array
edges, whereedges[i] = [u_i, v_i, w_i]represents an edge between nodesu_iandv_iwith weightw_i. The weightw_iis either 0 or 1.Process the edges in
edgesin the given order. For each edge, add it to the graph only if, after adding it, the sum of the weights of the edges in every cycle in the resulting graph is even.Return an integer denoting the number of edges that are successfully added to the graph.
1 |
|