cho.sh
Notes
Loading...

Traffic System

Time limit

2s

Memory limit

512 MB

Problem

A country has N cities and E bidirectional roads, each connecting two different cities. The cities are numbered from 1 to N. If a road connects two cities, it can be used in both directions.

The country wants to simplify this complex traffic system. There are two possible operations: remove one chosen road, or choose one city and remove every road entering or leaving that city.

Several questions are given to check how these operations affect reachability. Each question is one of the following two types.

  1. Cities A and B are given, along with a road connecting cities G1 and G2. After removing the road between G1 and G2, can you still travel from A to B?
  2. Cities A, B, and C are given. After removing every road connected to C, can you still travel from A to B?

Given the current traffic system and all questions, write a program that answers each question.

Input

The first line contains the number of cities N and the number of roads E. (2 <= N <= 100,000, 1 <= E <= 500,000)

Each of the next E lines contains the numbers of two different cities connected by a road. No road is given more than once, and the given traffic system always has at least one path between every pair of cities.

The next line contains the number of questions Q. (1 <= Q <= 300,000)

Each of the next Q lines contains one question. The first number on the line is the question type, either 1 or 2.

  • For type 1, the line is 1 A B G1 G2. A and B are different, and a road between G1 and G2 always exists.
  • For type 2, the line is 2 A B C. A, B, and C are all different cities.

Output

For each question, print one answer on its own line. Print yes if travel is still possible after the simplification, and no otherwise.