HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > CEN303 2013-15 Questions > problem:


14-Fall1-40. 50683 - Parking Buses

CEN303 2013-15 Questions

Start: Dec.15.2013 at 02:00:00 PM
Finish: Dec.15.2013 at 07:00:00 PM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (1)

Contest problems

• 50464 - From Tirana to Durres
• 13-Fall2-10. 50411 - Sum of the Lea...
• 13-Fall2-20. 50687 - Pascal Triangle - 2
• 13-Fall2-40. 50753 - Average of the...
• 13-Fall2-50. 50686 - The Container
• 14-Fall1-10. 50740 - Service Time - 1
• 14-Fall1-20. 50750 - Service Time - 2
• 14-Fall1-30. 50771 - BST Level Sum
• 14-Fall1-40. 50683 - Parking Bu...
• 14-Fall1-50. 50770 - Average Depth
• 14-Fall1-60. 50784 - Top Growing C...
• 14-Fall2-10. 50751 - The biggest Mi...
• 14-Fall2-20. 50794 - Writing Files Int...
• 14-Fall2-30. 50490 - Across the River
• 14-Fall2-40. 50772 - The Path of a N...
• 14-Fall2-50. 50681 - Center of a Series
• 14-FallResit-10. 50525 - Ordering Pizza

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 3090/9045/8000/4000 ms. Memory limit 15720/79180/65000/65000 Kb.
Question by Osman Ay, It has been first asked in IS 2012 March.

Parking Buses

Shqip

Tirana City has N buses, conveniently numbered from 1 to N, for public transportation. The buses are parked in a parking area at the end of everyday. The buses are parked side by side. They can be parked in any order but there are some restrictions that should be taken into the consideration. The restrictions are about the priority between two certain buses. Some buses should be parked before some other buses due to the schedule of the next day.

Question

Make a program that gives the number of restrictions that are not satisfied with the given order of buses.

Input Specifications

Input has several lines. The first line contains two integers: N and M, where N denotes the number of buses (1 < N ≤ 10000) and M (0 ≤ M ≤ 501000) denotes the number of restrictions. Each of the following M lines represent a restriction with a pair of integer X and Y(1 ≤ X, Y ≤ N). One pair states that bus X should be parked before the bus Y.

The last part of the input contains N integers that denote the available order of the buses. The buses are numbered from 1 to N and there are at most 40 buses in one line, that is, the lines contain less than 255 chars. )

Output Specifications

Give just one integer Res (where 0 ≤ Res ≤ M). That means there are Res restrictions which are not satisfied with the given bus order. If all the restrictions are satisfied with the current bus order, show 0 (zero).

Sample Input

6 7
1 3
2 4
1 6
5 4
4 6
3 6
2 1
2 3 1 5 6 4

Sample Output

2

Explanation for the sample output.

There are two restrictions (the first (1 3) and the fifth (4 6) restrictions) that does not satisfy the given conditions.

Для отправки решений необходимо выполнить вход.

www.contester.ru