Problem L: Large Of Company

Xem dạng PDF

Gửi bài giải

Điểm: 1,00
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Tác giả:
Dạng bài

Trong trường hợp đề bài hiển thị không chính xác, bạn có thể tải đề bài tại đây: Đề bài

In city, the company H&M operates ~N~ communication service stations (numbered from 1 to ~N~). To enhance the quality and security of data transmission, each station may have several direct cable connections to other stations. Information can be exchanged between stations bidirectionally via these cables. The communication system of H&M is considered stable if any two stations can exchange information with each other.

After the Aquar storm, some of the cables were severely damaged and need to be replaced. Among these, some cables cross rivers, and replacing them is far more expensive than replacing cables that are on land.

It is known that before the Aquar storm, the system was stable. Your task is to determine the total length of the cables that need to be repaired after the storm. If the system remains stable after the storm, the answer is 0.

Note that your solution should minimize the cost of repairs, giving priority to avoiding river-crossing cables whenever possible (i.e., only replace river-crossing cables if there is no other option).


Input

The first line contains four integers: ~N, M, D,~ and ~R,~ where:

• ~N~ is the number of stations,

• ~M~ is the number of cables,

• ~D~ is the number of damaged cables on land,

• ~R~ is the number of damaged cables that cross rivers.

It is guaranteed that ~0 ≤ N, M ≤ 10^5~ and ~0 ≤ D + R ≤ M~.

The next ~M~ lines describe the ~i^{th}~ cable, each containing three integers: ~u, v,~ and ~l~, which means station u is connected to station v by a cable of length l (1 ≤ l ≤ 1000).

The following ~D~ lines contain the index i of the damaged cables on land ~(1 ≤ i ≤ M)~.

The next ~R~ lines contain the index i of the damaged river-crossing cables ~(1 ≤ i ≤ M)~.


Output

Print the total length of the cables that need to be repaired after the storm


Sample Input 1

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

Sample Ouput 1

8

Sample Input 1

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

Sample Ouput 1

13

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.