CF1408E.Avoid Rainbow Cycles
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given m sets of integers A1,A2,…,Am; elements of these sets are integers between 1 and n, inclusive.
There are two arrays of positive integers a1,a2,…,am and b1,b2,…,bn.
In one operation you can delete an element j from the set Ai and pay ai+bj coins for that.
You can make several (maybe none) operations (some sets can become empty).
After that, you will make an edge-colored undirected graph consisting of n vertices. For each set Ai you will add an edge (x,y) with color i for all x,y∈Ai and x<y. Some pairs of vertices can be connected with more than one edge, but such edges have different colors.
You call a cycle i1→e1→i2→e2→…→ik→ek→i1 (ej is some edge connecting vertices ij and ij+1 in this graph) rainbow if all edges on it have different colors.
Find the minimum number of coins you should pay to get a graph without rainbow cycles.
给你 m 个整数集合 A1,A2,…,Am;这些集合中的元素均为介于 1 到 n(含)之间的整数。
另有两个正整数数组 a1,a2,…,am 和 b1,b2,…,bn。
一次操作定义为:从集合 Ai 中删除一个元素 j,并为此支付 ai+bj 枚金币。
你可以执行若干次(也可以不执行)此类操作(某些集合可能因此变为空集)。
之后,你将构造一个边染色的无向图,该图包含 n 个顶点。对于每个集合 Ai,你将在所有满足 x,y∈Ai 且 x<y 的顶点对 (x,y) 之间添加一条颜色为 i 的边。某些顶点对之间可能被多条边连接,但这些边的颜色互不相同。
我们称一个环 i1→e1→i2→e2→…→ik→ek→i1(其中每条边 ej 连接顶点 ij 和 ij+1,且下标按模 k 计算)为彩虹环(rainbow cycle),当且仅当该环上所有边的颜色互不相同。
求使最终图中不存在彩虹环所需支付的金币数的最小值。
输入格式
The first line contains two integers m and n (1≤m,n≤105), the number of sets and the number of vertices in the graph.
The second line contains m integers a1,a2,…,am (1≤ai≤109).
The third line contains n integers b1,b2,…,bn (1≤bi≤109).
In the each of the next of m lines there are descriptions of sets. In the i-th line the first integer si (1≤si≤n) is equal to the size of Ai. Then si integers follow: the elements of the set Ai. These integers are from 1 to n and distinct.
It is guaranteed that the sum of si for all 1≤i≤m does not exceed 2⋅105.
第一行包含两个整数 m 和 n(1≤m,n≤105),分别表示集合的数量和图中顶点的数量。
第二行包含 m 个整数 a1,a2,…,am(1≤ai≤109)。
第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤109)。
接下来的 m 行中,每行描述一个集合。第 i 行的第一个整数 si(1≤si≤n)表示集合 Ai 的大小;随后是 si 个整数:集合 Ai 的元素。这些整数均在 1 到 n 之间,且互不相同。
保证对所有 1≤i≤m,所有 si 的总和不超过 2⋅105。
输出格式
Print one integer: the minimum number of coins you should pay for operations to avoid rainbow cycles in the obtained graph.
输出一个整数:为避免所得图中出现彩虹环,你需要支付的最少硬币数量。
输入输出样例
输入#1
3 2 1 2 3 4 5 2 1 2 2 1 2 2 1 2
输出#1
11
输入#2
7 8 3 6 7 9 10 7 239 8 1 9 7 10 2 6 239 3 2 1 3 2 4 1 3 1 3 7 2 4 3 5 3 4 5 6 7 2 5 7 1 8
输出#2
66
说明/提示
In the first test, you can make such operations:
- Delete element 1 from set 1. You should pay a1+b1=5 coins for that.
- Delete element 1 from set 2. You should pay a2+b1=6 coins for that.
You pay 11 coins in total. After these operations, the first and the second sets will be equal to 2 and the third set will be equal to 1,2.
So, the graph will consist of one edge (1,2) of color 3.
In the second test, you can make such operations:
- Delete element 1 from set 1. You should pay a1+b1=11 coins for that.
- Delete element 4 from set 2. You should pay a2+b4=13 coins for that.
- Delete element 7 from set 3. You should pay a3+b7=13 coins for that.
- Delete element 4 from set 4. You should pay a4+b4=16 coins for that.
- Delete element 7 from set 6. You should pay a6+b7=13 coins for that.
You pay 66 coins in total.
After these operations, the sets will be:
- 2,3;
- 1;
- 1,3;
- 3;
- 3,4,5,6,7;
- 5;
- 8.
We will get the graph:

There are no rainbow cycles in it.
在第一个测试用例中,你可以执行如下操作:
- 从集合 1 中删除元素 1。为此你需要支付 a1+b1=5 枚金币。
- 从集合 2 中删除元素 1。为此你需要支付 a2+b1=6 枚金币。
你总共支付了 11 枚金币。执行这些操作后,第一个和第二个集合均变为 {2},第三个集合变为 {1,2}。
因此,所得图包含一条颜色为 3 的边 (1,2)。
在第二个测试用例中,你可以执行如下操作:
- 从集合 1 中删除元素 1。为此你需要支付 a1+b1=11 枚金币。
- 从集合 2 中删除元素 4。为此你需要支付 a2+b4=13 枚金币。
- 从集合 3 中删除元素 7。为此你需要支付 a3+b7=13 枚金币。
- 从集合 4 中删除元素 4。为此你需要支付 a4+b4=16 枚金币。
- 从集合 6 中删除元素 7。为此你需要支付 a6+b7=13 枚金币。
你总共支付了 66 枚金币。
执行这些操作后,各集合变为:
- {2,3};
- {1};
- {1,3};
- {3};
- {3,4,5,6,7};
- {5};
- {8}。
我们得到如下图:

该图中不存在彩虹环。
输入解题思路,AI测评打分。不知道怎么写?