CF2115E.Gellyfish and Mayflower

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mayflower by Plum

May, Gellyfish's friend, loves playing a game called "Inscryption" which is played on a directed acyclic graph with nn vertices and mm edges. All edges $ a \rightarrow b$ satisfy a<ba \lt b.

You start in vertex 11 with some coins. You need to move from vertex 11 to the vertex where the boss is located along the directed edges, and then fight with the final boss.

Each of the nn vertices of the graph contains a Trader who will sell you a card with power wiw_i for cic_i coins. You can buy as many cards as you want from each Trader. However, you can only trade with the trader on the ii-th vertex if you are currently on the ii-th vertex.

In order to defeat the boss, you want the sum of the power of your cards to be as large as possible.

You will have to answer the following qq queries:

  • Given integers pp and rr. If the final boss is located at vertex pp, and you have rr coins in the beginning, what is the maximum sum of the power of your cards when you fight the final boss? Note that you are allowed to trade cards on vertex pp.

《五月花》——Plum

五月(May)是水母(Gellyfish)的朋友,她热衷于玩一款名为“Inscryption”的游戏。该游戏在一个具有 nn 个顶点和 mm 条边的有向无环图(DAG)上进行,且所有边 $ a \rightarrow b$ 均满足 a<ba \lt b。

你从顶点 11 出发,携带若干枚金币。你需要沿着有向边从顶点 11 移动至最终 Boss 所在的顶点,然后与 Boss 战斗。

图中每个顶点 ii 上均有一位商人,可向你出售一张力量值为 wiw_i、售价为 cic_i 枚金币的卡牌。你可从每位商人处购买任意数量的卡牌。但仅当你恰好位于顶点 ii 时,才可与该顶点上的商人交易。

为击败 Boss,你希望所持卡牌的总力量值尽可能大。

你需要回答以下 qq 个查询:

  • 给定整数 pp 和 rr。若最终 Boss 位于顶点 pp,且你初始拥有 rr 枚金币,则你在与 Boss 战斗时所能达到的最大卡牌总力量值是多少?注意:你可以在顶点 pp 处与商人交易。

输入格式

The first line of input contains two integers nn and mm (1≤n≤2001 \leq n \leq 200, n−1≤m≤min⁡(n(n−1)2,2000)n - 1 \leq m \leq \min(\frac {n(n-1)} 2, 2000)) — the number of vertices and the number of edges.

The ii-th of the following nn lines of input each contains two integers cic_i and wiw_i (1≤ci≤2001 \leq c_i \leq 200, 1≤wi≤1091 \leq w_i \leq 10^9) — describing the cards of the Trader on the ii-th vertex.

In the following mm lines of input, each line contains two integers uu and vv (1≤u<v≤n1 \leq u \lt v \leq n), indicating a directed edge from vertex uu to vertex vv. It is guaranteed that every edge (u,v)(u,v) appears at most once.

The next line of input contains one single integer qq (1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5) — the number of queries.

In the following qq lines of input, each line contains two integers pp and rr (1≤p≤n1 \leq p \leq n, 1≤r≤1091 \leq r \leq 10^9).

It is guaranteed that for all ii, there exists a path from vertex 11 to vertex ii.

输入的第一行包含两个整数 nn 和 mm(1≤n≤2001 \leq n \leq 200,n−1≤m≤min⁡(n(n−1)2,2000)n - 1 \leq m \leq \min(\frac {n(n-1)} 2, 2000)),分别表示顶点数和边数。

接下来的 nn 行中,第 ii 行包含两个整数 cic_i 和 wiw_i(1≤ci≤2001 \leq c_i \leq 200,1≤wi≤1091 \leq w_i \leq 10^9),描述位于第 ii 个顶点上的交易员所持有的卡片。

接下来的 mm 行中,每行包含两个整数 uu 和 vv(1≤u<v≤n1 \leq u \lt v \leq n),表示一条从顶点 uu 指向顶点 vv 的有向边。保证每条边 (u,v)(u,v) 至多出现一次。

接下来的一行包含一个整数 qq(1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5),表示查询次数。

接下来的 qq 行中,每行包含两个整数 pp 和 rr(1≤p≤n1 \leq p \leq n,1≤r≤1091 \leq r \leq 10^9)。

保证对所有 ii,均存在一条从顶点 11 到顶点 ii 的路径。

输出格式

For each query, output the answer to the query.

对于每个查询,输出该查询的答案。

输入输出样例

  • 输入#1

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

    输出#1

    9
    10
    11
    9
    14
    14
  • 输入#2

    4 4
    10 1000
    2 5
    1 2
    3 9
    1 2
    1 3
    2 4
    3 4
    9
    2 3
    3 3
    4 1
    4 2
    4 4
    4 5
    4 101
    4 102
    4 103

    输出#2

    5
    6
    2
    5
    11
    14
    10002
    10005
    10009
  • 输入#3

    6 8
    9 5
    4 1
    8 9
    10 4
    9 4
    8 2
    3 5
    4 6
    3 4
    2 3
    1 2
    2 5
    4 5
    1 3
    10
    3 12
    1 9
    6 47
    2 19
    1 129
    5 140
    2 148
    1 63
    2 43
    3 102

    输出#3

    10
    5
    46
    10
    70
    154
    81
    35
    21
    109

说明/提示

For the third query in the first example, we will play the game in the following order:

  • buy 11 card with 99 power from the trader on vertex 11, and you'll still have 11 coin after the trade.
  • move from vertex 11 to vertex 22.
  • move from vertex 22 to vertex 33.
  • buy 11 card with 22 power from the trader on vertex 33, and you'll have no coins after the trade.

In the end, we will have 11 card with 99 power and 11 card with 22, so the sum of the power of the cards is 9+2=119+2=11.

For the fifth query in the second example, we will play the game in the following order:

  • move from vertex 11 to vertex 33.
  • buy 11 card with 22 power from the trader on vertex 33, and you'll still have 33 coins after the trade.
  • move from vertex 33 to vertex 44.
  • buy 11 card with 99 power from the trader on vertex 44, and you'll have no coins after the trade.

In the end, we will have 11 card with 22 power and 11 card with 99, so the sum of the power of the cards is 2+9=112+9=11.

For the sixth query in the second example, we will play the game in the following order:

  • move from vertex 11 to vertex 22.
  • buy 11 card with 55 power from the trader on vertex 22, and you'll still have 33 coins after the trade.
  • move from vertex 22 to vertex 44.
  • buy 11 card with 99 power from the trader on vertex 44, and you'll have no coins after the trade.

In the end, we will have 11 card with 55 power and 11 card with 99, so the sum of the power of the cards is 5+9=145+9=14.

For the seventh query in the second example, we will play the game in the following order:

  • buy 1010 cards with 10001000 power from the trader on vertex 11, and you'll still have 11 coin after the trade.
  • move from vertex 11 to vertex 33.
  • buy 11 card with 22 power from the trader on vertex 33, and you'll have no coins after the trade.
  • move from vertex 33 to vertex 44.

In the end, we will have 1010 cards with 10001000 power and 11 card with 22 power, so the sum of the power of the cards is 10⋅1000+2=10 00210 \cdot 1000+2=10\,002.

对于第一个样例中的第三次查询,我们将按以下顺序进行游戏:

  • 在顶点 11 的商人处购买 11 张力量值为 99 的卡牌,交易后还剩余 11 枚金币。
  • 从顶点 11 移动到顶点 22。
  • 从顶点 22 移动到顶点 33。
  • 在顶点 33 的商人处购买 11 张力量值为 22 的卡牌,交易后金币数为 00。

最终,我们将拥有 11 张力量值为 99 的卡牌和 11 张力量值为 22 的卡牌,因此卡牌力量值总和为 9+2=119+2=11。

对于第二个样例中的第五次查询,我们将按以下顺序进行游戏:

  • 从顶点 11 移动到顶点 33。
  • 在顶点 33 的商人处购买 11 张力量值为 22 的卡牌,交易后还剩余 33 枚金币。
  • 从顶点 33 移动到顶点 44。
  • 在顶点 44 的商人处购买 11 张力量值为 99 的卡牌,交易后金币数为 00。

最终,我们将拥有 11 张力量值为 22 的卡牌和 11 张力量值为 99 的卡牌,因此卡牌力量值总和为 2+9=112+9=11。

对于第二个样例中的第六次查询,我们将按以下顺序进行游戏:

  • 从顶点 11 移动到顶点 22。
  • 在顶点 22 的商人处购买 11 张力量值为 55 的卡牌,交易后还剩余 33 枚金币。
  • 从顶点 22 移动到顶点 44。
  • 在顶点 44 的商人处购买 11 张力量值为 99 的卡牌,交易后金币数为 00。

最终,我们将拥有 11 张力量值为 55 的卡牌和 11 张力量值为 99 的卡牌,因此卡牌力量值总和为 5+9=145+9=14。

对于第二个样例中的第七次查询,我们将按以下顺序进行游戏:

  • 在顶点 11 的商人处购买 1010 张力量值为 10001000 的卡牌,交易后还剩余 11 枚金币。
  • 从顶点 11 移动到顶点 33。
  • 在顶点 33 的商人处购买 11 张力量值为 22 的卡牌,交易后金币数为 00。
  • 从顶点 33 移动到顶点 44。

最终,我们将拥有 1010 张力量值为 10001000 的卡牌和 11 张力量值为 22 的卡牌,因此卡牌力量值总和为 10⋅1000+2=10 00210 \cdot 1000+2=10\,002。

输入解题思路,AI测评打分。不知道怎么写?

首页