Under construction

Still being built. Things may change

Occupation

Interview

Time limit3sMemory limit1024 MB

Summary
Starting from node r, capture adjacent nodes whose requirement A_i is at most your current stamina, gain B_i for each, and find the final stamina.
Level

Medium4 of 10

Topics
Greedy, Heap, Graph
Solved
No attempts yet

Problem

You are given an undirected graph and a starting node rr. The nodes are numbered 1,2,…,N1,2,\dots,N. To capture node ii, you must have at least AiA_i stamina and at least one neighbor of node ii must already be captured. After you capture node ii, your stamina increases by BiB_i. Capturing a node does not decrease your stamina by AiA_i. Find the maximum stamina you can obtain. The start node is already captured, so your stamina at the start is BrB_r.

Input

The first line contains the number of nodes NN, the number of edges MM, and the start node rr, separated by spaces. (1≤N≤500 0001 \le N \le 500\,000; 0≤M≤1 000 0000 \le M \le 1\,000\,000; 1≤r≤N1 \le r \le N)

The second line contains A1,A2,…,ANA_1, A_2, \dots, A_N, separated by spaces, the stamina required to capture each node. (0≤Ai≤1090 \le A_i \le 10^9; Ar=0A_r=0)

The third line contains B1,B2,…,BNB_1, B_2, \dots, B_N, separated by spaces, the stamina gained by capturing each node. (0≤Bi≤1090 \le B_i \le 10^9)

From the fourth line onward, MM lines each contain two integers uu and vv, separated by a space, meaning that uu and vv are neighbors. (1≤u,v≤N1 \le u, v \le N; u≠vu \ne v)

Output

Print the maximum stamina you can obtain.

Examples1

  1. Example 1

    Input
    3 2 2
    10 0 3
    100 3 4
    1 2
    2 3
    
    Expected output
    7