CF1487E.Cheap Dinner

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.

There are n1n_1 different types of first courses Ivan can buy (the ii -th of them costs aia_i coins), n2n_2 different types of second courses (the ii -th of them costs bib_i coins), n3n_3 different types of drinks (the ii -th of them costs cic_i coins) and n4n_4 different types of desserts (the ii -th of them costs did_i coins).

Some dishes don't go well with each other. There are m1m_1 pairs of first courses and second courses that don't go well with each other, m2m_2 pairs of second courses and drinks, and m3m_3 pairs of drinks and desserts that don't go well with each other.

Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!

输入格式

The first line contains four integers n1n_1 , n2n_2 , n3n_3 and n4n_4 ( 1ni1500001 \le n_i \le 150000 ) — the number of types of first courses, second courses, drinks and desserts, respectively.

Then four lines follow. The first line contains n1n_1 integers a1,a2,,an1a_1, a_2, \dots, a_{n_1} ( 1ai1081 \le a_i \le 10^8 ), where aia_i is the cost of the ii -th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way ( 1bi,ci,di1081 \le b_i, c_i, d_i \le 10^8 ).

The next line contains one integer m1m_1 ( 0m12000000 \le m_1 \le 200000 ) — the number of pairs of first and second courses that don't go well with each other. Each of the next m1m_1 lines contains two integers xix_i and yiy_i ( 1xin11 \le x_i \le n_1 ; 1yin21 \le y_i \le n_2 ) denoting that the first course number xix_i doesn't go well with the second course number yiy_i . All these pairs are different.

The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other ( 0m2,m32000000 \le m_2, m_3 \le 200000 ).

输出格式

If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print 1-1 . Otherwise, print one integer — the minimum total cost of the dinner.

输入输出样例

  • 输入#1

    4 3 2 1
    1 2 3 4
    5 6 7
    8 9
    10
    2
    1 2
    1 1
    2
    3 1
    3 2
    1
    1 1

    输出#1

    26
  • 输入#2

    1 1 1 1
    1
    1
    1
    1
    1
    1 1
    0
    0

    输出#2

    -1

说明/提示

The best option in the first example is to take the first course 22 , the second course 11 , the drink 22 and the dessert 11 .

In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.

首页