QOJ.ac

QOJ

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

#4785. 有向图

统计

给定一个 $n$ 个点 $m$ 条边的有向弱连通图, 每个点均有点权 $d_i$ 和修改耗时 $w_i$, 每次修改可以花费 $w_i$ 的时间把 $d_i$ 加 $1$ 或者减 $1$,求最少消耗多少时间,使得 $\forall (u,v)\in E, d_u\le d_v$。

输入格式

输入共包括 $m+3$ 行

第一行包含两个整数 $n,m$,表示点数和边数。

第二行包含 $n$ 个整数,第 $i$ 个整数表示第 $i$ 个点的点权 $d_i$。

第三行包含 $n$ 个整数,第 $i$ 个整数表示第 $i$ 个点的修改耗时 $w_i$。

第 $4 ~ m+3$ 行,每行包含两个整数 $u_i,v_i$,表示有向图种的一条由 $u_i$ 到 $v_i$ 的有向边。

输出格式

输出包含一个整数,表示最小总耗时。

样例数据

样例 1 输入

3 3
5 9 8
1 2 3
1 2
2 3
3 1

样例 1 输出

5

样例 1 解释

限制为 $d_1\le d_2,d_2\le d_3,d_3\le d_1$,即要求 $d_1 = d_2 = d_3$,故将 $d_1$ 加 $3$ 至 $8$,$d_2$ 减 $1$ 至 $8$ 最优,最小耗时为 $1 \times |5-8| + 2\times |9-8| + 3 \times |8-8| = 5$。

样例 2 输入

3 2
5 9 8
1 2 3
1 2
2 3

样例 2 输出

2

子任务

子任务 分值 $n \leq $ $m=$ 特殊限制
$1$ $10$ $5000$ $n-1$
$2$ $20$ $100000$ 将所有有向边看成无向边时,整张图构成一条链
$3$ $20 $
$4$ $15$ $300000$
$5$ $10$ $n$ 存在数列$f_i$,满足有且仅有$i$向$f_i$的有向边,$w_i=1$
$6$ $10 $ 将所有有向边看成无向边时,整张图构成一个环
$7$ $15$ $n-1,n$
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.