Connectivity Queries (DSU) (OOP)

Programming Interview Hard 9 views
Back to Questions

Problem Description

Input provides {x}. Make DSU class with find and union. Queries: UNION u v, ASK u v. For ASK output YES if connected else NO.

Input Format

First line n q. Next q lines queries.

Output Format

Outputs for ASK lines.

Sample Test Case

Input:
5 6 UNION 1 2 ASK 1 3 UNION 2 3 ASK 1 3 ASK 4 5 UNION 4 5
Output:
NO YES NO

Constraints

1

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next