Skip to content

Commit

Permalink
Fixed editorial.md
Browse files Browse the repository at this point in the history
  • Loading branch information
VarunMK committed Sep 25, 2021
1 parent af78f6a commit 8479338
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions editorials/problems/CNCTS/editorial.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
So for the first subtask, all we had to do is use DFS to check how many places can be visited by the given city after adding the roads.
So for each query of type 2, it would take O(N) time complexity.
For the first subtask, all we had to do is use DFS to check how many places can be visited by the given city after adding the roads.
For each query of type 2, it would take O(N) time complexity.
For Q queries, the total time complexity would be O(NQ) which fits the given constraints.

For the second subtask, we need a faster solution. So for this, we would use a structure called DSU or disjoint set union.
For the second subtask, we need a faster solution. For this, we would use a structure called DSU or disjoint set union.
For queries of type 1, we would `merge` (or in other words apply the `union`) the two cities. This takes O(logN) time complexity for each query.

As for query 2, we need another data structure within our DSU which stores the size (or in this case, the number of cities we can visit) for each set (or in this case, city).
If we do this, we can reduce the time taken to retrieve the size to just O(1).

So for Q queries our worst case time complexity would be just O(Q log N).
For Q queries our worst case time complexity would be just O(Q log N).

0 comments on commit 8479338

Please sign in to comment.