Cut Vertices and Bridges
InterviewTime limit1sMemory limit512 MB
Given a tree with N vertices and queries, report for each query whether a specified vertex is a cut vertex or a specified edge is a bridge.
- Level
Medium4 of 10
- Topics
- Tree, DFS, Graph, Implementation
- Solved
- No attempts yet
Problem
In graph theory, a cut vertex and a bridge are defined as follows.
- Cut vertex: if deleting a vertex splits the connected component that contained it into two or more components, that vertex is a cut vertex.
- Bridge: if deleting an edge splits the connected component that contained it into two or more components, that edge is a bridge.
This problem asks for cut vertices and bridges of a tree. A tree is a graph with no cycle in which every vertex is connected.
Given a tree and a list of queries, answer each query.
Input
Input comes from standard input. The first line has the number of vertices of the tree. () The vertices are numbered from 1 to . Each of the next lines has an edge and , meaning vertex and vertex are connected. The given graph is always a tree. ()
The next line has the number of queries . () Each of the next lines has a query and . () If is 1, the query asks whether vertex is a cut vertex. If is 2, the query asks whether the -th edge of the input is a bridge. When is 1, . When is 2, .
Output
Print to standard output. For the queries, print one answer per line. Print yes if the queried vertex is a cut vertex or the queried edge is a bridge, and no otherwise.