#t527. 搭配购买

搭配购买

Combined Purchase

Problem Background

Special for beginners, ^_^

Problem Description

Joe thinks clouds are beautiful, so he decides to go to the mountain shop to buy some clouds. The shop has nn clouds, numbered 1,2,…,n1, 2, \dots, n, and each cloud has a value. But the shopkeeper tells him that some clouds must be bought together to be worthwhile, so buying one cloud also requires buying all the clouds matched with it.

However, Joe has limited money, so he wants to get as much value as possible.

Input Format

The first line contains n,m,wn, m, w, meaning nn clouds, mm matches, and Joe has ww money.

Lines 22 to n+1n+1: each line contains ci,dic_i, d_i, the price and the value of the ii-th cloud.

Lines n+2n+2 to n+1+mn+1+m: each line contains ui,viu_i, v_i, meaning buying uiu_i requires buying viv_i, and similarly buying viv_i requires buying uiu_i.

Output Format

One line: the maximum value obtainable.

Sample Input

5 3 10
3 10
3 10
3 10
5 100
10 1
1 3
3 2
4 2

Sample Output

1

Constraints

Time limit: 1s; memory limit: 1024 KiB for each test case.

For 30%30\% of the data: n≤100n \le 100.

For 50%50\% of the data: n≤1000n \le 1000, m≤100m \le 100, w≤1000w \le 1000.

For 100%100\% of the data: n≤10000n \le 10000, 0≤m≤50000 \le m \le 5000, w≤10000w \le 10000.