luogu#P12195. [NOISG 2025 Prelim] Itinerary
[NOISG 2025 Prelim] Itinerary
题目描述
The Scientific Committee is planning to visit cities. The cities are connected by exactly roads such that it is possible to move between all pairs of cities using the roads. Road is built between cities and .
Each city has its own airport. To begin the trip, the committee will fly from Singapore to one of the cities. To make the most out of their trip in the most efficient way possible, the committee wants to visit each city at least once by using each road exactly twice (once in each direction), before flying back home from the last city they find themselves in. A trip satisfying this condition is called a tour.
For example, let the diagram above represent a map of cities. One possible tour starting from city is $1 \to 3 \to 5 \to 3 \to 4 \to 2 \to 8 \to 2 \to 4 \to 6 \to 4 \to 7 \to 4 \to 3 \to 1$. Observe that this tour visits all cities a total of (equal to ) times and ends at the same city it started from (city ). It can be shown that these two properties are true for all tours in all possible maps of cities.
The committee also wants to visit events which will happen in order from event to event . Event will be held in city . A city can hold zero, one or multiple events, but no two consecutive events are held in the same city, i.e., .
A tour that allows the committee to visit all events must visit the cities in order, not necessarily consecutively. Such a tour is called an itinerary. Formally, let be the sequence of cities visited in some tour. A tour is an itinerary if and only if is a subsequence of . That is, can be obtained by deleting zero or more elements from and maintaining the order of the remaining elements. Using the same example as above, suppose that and , then the tour $1 \to \textbf{3} \to \textbf{5} \to 3 \to 4 \to \textbf{2} \to 8 \to 2 \to 4 \to 6 \to 4 \to \textbf{7} \to 4 \to 3 \to 1$ above is an itinerary because the cities are visited in order during the tour (underlined and marked in bold).
The committee is still deciding which city to start from, but they agree that a city is a good choice to start from if there exists an itinerary that starts from it. For all cities, help the committee determine if there exists at least one itinerary starting from that city.
输入格式
Your program must read from standard input.
The first line of input contains two space-separated integers and , describing the number of cities and the number of events respectively.
The following lines of input each contain two space-separated integers. The -th of these lines contains and , describing the endpoints of the -th road.
The last line of input contains space-separated integers , describing the cities that are holding events.
输出格式
Your program must print to standard output.
The output should contain lines. If there exists an itinerary starting from city , then the -th line should contain a single integer . Otherwise, the -th line should contain a single integer .
8 4
1 3
2 4
3 4
4 6
5 3
2 8
7 4
3 5 2 7
1
0
1
1
0
1
1
0
8 4
1 3
2 4
3 4
4 6
5 3
2 8
7 4
3 2 5 7
0
0
0
0
0
0
0
0
4 7
1 2
1 3
1 4
2 1 2 1 2 1 2
0
0
0
0
5 2
1 2
2 3
3 4
4 5
2 4
1
1
1
1
1
提示
Subtasks
For all test cases, the input will satisfy the following bounds:
- for all
- for all
- for all
- It is possible to move between all pairs of cities using the roads.
Your program will be tested on input instances that satisfy the following restrictions:
Subtask | Marks | Additional Constraints |
---|---|---|
Sample test cases | ||
No additional constraints |
Sample Test Case 1 Explanation
This test case is valid for subtasks , and .
This test case is described as an example in the problem statement.
There are itineraries starting from cities , and . An itinerary starting from city is given in the problem statement.
On the other hand, it can be shown that there are no itineraries starting from cities , and .
Sample Test Case 2 Explanation
This test case is valid for subtasks , and .
This test case is the same as the example in the problem statement, except and are swapped. No itineraries exist at all.
Sample Test Case 3 Explanation
This test case is valid for subtasks , and .
Sample Test Case 4 Explanation
This test case is valid for subtasks , and .