Skip to content

Commit

Permalink
Merge pull request #19 from pes-alcoding-club/Sept2021
Browse files Browse the repository at this point in the history
Fixed editorial.md
  • Loading branch information
VarunMK authored Sep 25, 2021
2 parents f21f932 + 8479338 commit ce6b57d
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 ce6b57d

Please sign in to comment.