#DSU0000073. Bãi đỗ xe (Parking)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bãi đỗ xe (Parking)
Parking
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A parking lot has spaces and two-way roads. The entrance is connected to space . Initially all spaces are empty and every space is reachable from .
People arrive in order. Person will park only in space . They can do so if there is a path from the entrance to that space using only unoccupied spaces. If successful, space becomes occupied and cannot be traversed later; otherwise the person leaves. List all people who successfully park.
The entrance leads directly to parking space . To park at space , a driver must be able to reach it from the entrance using only currently vacant spaces. If space has already been occupied, later drivers cannot pass through it to reach any other space.
A driver who cannot park leaves without occupying any space. Only successful drivers change the parking lot's state. Print only the indices of those drivers, in increasing order.
Input
The first line contains . The next lines describe roads .
Output
Print the indices of all successful people in increasing order, one per line.
Subtasks
- Subtask 1 (20 points): ; ; ; , ; the initial graph is connected.
- Subtask 2 (30 points): ; ; ; , ; the initial graph is connected.
- Subtask 3 (50 points): ; ; ; , ; the initial graph is connected.
Examples
Input
3 3 2
1 2
2 3
1 3
Output
1
2
Explanation
Driver reaches space through space and parks. Driver parks at space , directly beside the entrance. Since this space is now occupied, driver cannot enter the lot to reach space , even though spaces and are connected. The successful drivers are and .