QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#913. 蝴蝶图

統計

看着蝴蝶扑不过天涯,谁又有权不理解。


我们称一张无向图连带其上的两个点集 $L,R$ 是蝴蝶图当且仅当满足以下条件:

  • $L\cup R$ 是整个点集。
  • $L\cap R$ 非空。
  • $L$ 中的任意两点可以只经过 $L$ 中的点互相到达。
  • $R$ 中的任意两点可以只经过 $R$ 中的点互相到达。

给定一张有边权的蝴蝶图,求出一个边权和最小的边集,使得保留这个边集之后原图仍是蝴蝶图。

输入格式

第一行输入四个正整数 $n,m,l,r$,表示图的点数,边数以及 $L,R$ 的大小。

接下来 $m$ 行每行输入三个正整数 $u,v,w$ 表示一条边。

接下来一行 $l$ 个正整数表示点集 $L$。

接下来一行 $r$ 个正整数表示点集 $R$。

输出格式

输出一行一个正整数,表示最小的边权和。

样例数据

样例 1 输入

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

样例 1 输出

9

样例 2 输入

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

样例 2 输出

10

子任务

对于 $100\%$ 的数据,保证 $1\le n\le 10^5; n - 1\le m\le 2\times 10^5; 1\le l + r - n\le 11; 1\le u,v\le n; 1\le w\le 10^9$,且给定的图连带集合 $L,R$ 构成一张蝴蝶图。

对于 $50\%$ 的数据,保证 $n=100$,另外 $50\%$ 的数据保证 $n=10^5$。

它们各自有 $10$ 个测试点,测试点中 $l+r-n$ 的值分别为 $1,3,4,5,6,7,8,9,10,11$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.