CF1383F.Special Edges

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Koa the Koala has a directed graph GG with nn nodes and mm edges. Each edge has a capacity associated with it. Exactly kk edges of the graph, numbered from 11 to kk, are special, such edges initially have a capacity equal to 00.

Koa asks you qq queries. In each query she gives you kk integers w1,w2,…,wkw_1, w_2, \ldots, w_k. This means that capacity of the ii-th special edge becomes wiw_i (and other capacities remain the same).

Koa wonders: what is the maximum flow that goes from node 11 to node nn after each such query?

Help her!

考拉熊 Koa 有一张有向图 GG,包含 nn 个节点和 mm 条边。每条边都具有一个容量。图中恰好有 kk 条边是特殊的(编号从 11 到 kk),这些特殊边的初始容量均为 00。

Koa 向你提出 qq 个查询。在每个查询中,她给出 kk 个整数 w1,w2,…,wkw_1, w_2, \ldots, w_k,表示第 ii 条特殊边的容量变为 wiw_i(其余边的容量保持不变)。

Koa 想知道:每次这样的查询之后,从节点 11 到节点 nn 的最大流是多少?

请帮帮她!

输入格式

The first line of the input contains four integers nn, mm, kk, qq (2≤n≤1042 \le n \le 10^4, 1≤m≤1041 \le m \le 10^4, 1≤k≤min⁡(10,m)1 \le k \le \min(10, m), 1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of nodes, the number of edges, the number of special edges and the number of queries.

Each of the next mm lines contains three integers uu, vv, ww (1≤u,v≤n1 \le u, v \le n; 0≤w≤250 \le w \le 25) — the description of a directed edge from node uu to node vv with capacity ww.

Edges are numbered starting from 11 in the same order they are listed in the input. The first kk edges are the special edges. It is guaranteed that wi=0w_i = 0 for all ii with 1≤i≤k1 \le i \le k.

Each of the next qq lines contains kk integers w1,w2,…,wkw_1, w_2, \ldots, w_k (0≤wi≤250 \le w_i \le 25) — the description of the query. wiw_i denotes the capacity of ii-th edge.

输入的第一行包含四个整数 nn、mm、kk、qq(2≤n≤1042 \le n \le 10^4,1≤m≤1041 \le m \le 10^4,1≤k≤min⁡(10,m)1 \le k \le \min(10, m),1≤q≤2⋅1051 \le q \le 2 \cdot 10^5),分别表示节点数、边数、特殊边数以及查询次数。

接下来的 mm 行,每行包含三个整数 uu、vv、ww(1≤u,v≤n1 \le u, v \le n;0≤w≤250 \le w \le 25),表示一条从节点 uu 指向节点 vv 的有向边,其容量为 ww。

边按输入顺序从 11 开始编号。前 kk 条边为特殊边。保证对所有满足 1≤i≤k1 \le i \le k 的 ii,均有 wi=0w_i = 0。

接下来的 qq 行,每行包含 kk 个整数 w1,w2,…,wkw_1, w_2, \ldots, w_k(0≤wi≤250 \le w_i \le 25),表示一次查询。其中 wiw_i 表示第 ii 条边的容量。

输出格式

For the ii-th query, print one integer resires_i — the maximum flow that can be obtained from node 11 to node nn given the ii-th query's special edge weights.

对于第 ii 个查询,输出一个整数 resires_i —— 在第 ii 个查询所指定的特殊边权重下,从节点 11 到节点 nn 能获得的最大流。

输入输出样例

  • 输入#1

    2 1 1 3
    1 2 0
    0
    1
    2

    输出#1

    0
    1
    2
  • 输入#2

    4 4 2 5
    1 2 0
    2 3 0
    2 4 5
    3 4 2
    0 0
    1 10
    10 0
    7 1
    7 2

    输出#2

    0
    1
    5
    6
    7

说明/提示

For the second sample, the following images correspond to the first two queries (from left to right respectively). For each edge there is a pair flow/capacity denoting flow pushed through the edge and edge's capacity. The special edges are colored in red.

As you can see in first query maximum flow from node 11 to node 44 equals 00 and in second query equals 11.

对于第二个样例,以下图片分别对应前两个查询(从左到右)。每条边上标有一对数值“流量/容量”,分别表示经该边推送的流量及该边的容量。特殊边以红色标出。

如图所示,第一个查询中从节点 11 到节点 44 的最大流为 00,第二个查询中则为 11。

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

首页