Problem Statement There is an undirected graph with N vertices and 0 edges. The vertices…
- User
Problem Statement There is an undirected graph with N vertices and 0 edges. The vertices are numbered 1 to N.
You are given Q queries to process in order. Each query is of one of the following two types:
Type 1: Given in the format 1 u v. Add an edge between vertices u and v. Type 2: Given in the format 2 v k. Print the k-th largest vertex number among the vertices connected to vertex v. If there are fewer than k vertices connected to v, print -1. Constraints 1≤N,Q≤2×10 5
In a Type 1 query, 1≤u<v≤N. In a Type 2 query, 1≤v≤N, 1≤k≤10. All input values are integers. Input The input is given from Standard Input in the following format:
N Q query 1
query 2
⋮ query Q
Here, query i is the i-th query and is given in one of the following formats:
1 u v 2 v k Output Let q be the number of Type 2 queries. Print q lines. The i-th line should contain the answer to the i-th Type 2 query.
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.