QOJ.ac

QOJ

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

#913. 蝴蝶図

Statistics

蝶が天涯を越えられないのを見て、誰が理解しない権利を持つだろうか。

無向グラフと、その上の2つの頂点集合 $L, R$ が蝶グラフであるとは、以下の条件を満たすことをいう。

  • $L \cup R$ が全頂点集合である。
  • $L \cap R$ は空ではない。
  • $L$ 内の任意の2点は、$L$ 内の頂点のみを通って互いに到達可能である。
  • $R$ 内の任意の2点は、$R$ 内の頂点のみを通って互いに到達可能である。

辺重みを持つ蝶グラフが与えられる。この辺集合の一部を残してグラフが依然として蝶グラフである状態を保つとき、残す辺の重みの総和の最小値を求めよ。

入力

1行目に4つの正整数 $n, m, l, r$ が与えられる。これらはそれぞれグラフの頂点数、辺数、および $L, R$ のサイズを表す。

続く $m$ 行には、各辺を表す3つの正整数 $u, v, w$ が与えられる。

続く1行には、$L$ に含まれる $l$ 個の正整数が与えられる。

続く1行には、$R$ に含まれる $r$ 個の正整数が与えられる。

出力

最小の辺重みの総和を1行で出力せよ。

入出力例

入力 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

小課題

すべてのデータにおいて、$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$ である。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.