CF843D.Dynamic Shortest Path

NOI/NOI+/CTSC

通过率:0%

时间限制:10.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given a weighted directed graph, consisting of n vertices and m edges. You should answer q queries of two types:

  • 1 v — find the length of shortest path from vertex 1 to vertex v.
  • 2 c _l_1 _l_2 ... l__c — add 1 to weights of edges with indices _l_1, _l_2, ..., l__c.

给你一个带权有向图,包含 nn 个顶点和 mm 条边。你需要回答 qq 个查询,查询分为两类:

  • 1 v — 求从顶点 11 到顶点 vv 的最短路径长度;
  • 2 c l_1 l_2 ... l_c — 将编号为 l1, l2, ..., lcl_1,\,l_2,\,...,\,l_c 的边的权重各加 11。

输入格式

The first line of input data contains integers n, m, q (1 ≤ n, m ≤ 105, 1 ≤ q ≤ 2000) — the number of vertices and edges in the graph, and the number of requests correspondingly.

Next m lines of input data contain the descriptions of edges: i-th of them contains description of edge with index i — three integers a__i, b__i, c__i (1 ≤ a__i, b__i ≤ n, 0 ≤ c__i ≤ 109) — the beginning and the end of edge, and its initial weight correspondingly.

Next q lines of input data contain the description of edges in the format described above (1 ≤ v ≤ n, 1 ≤ l__j ≤ m). It's guaranteed that inside single query all l__j are distinct. Also, it's guaranteed that a total number of edges in all requests of the second type does not exceed 106.

输入数据的第一行包含整数 nn、mm、qq(1 ≤ n, m ≤ 1051 ≤ n, m ≤ 10^5,1 ≤ q ≤ 20001 ≤ q ≤ 2000),分别表示图中顶点数、边数以及查询次数。

接下来的 mm 行输入数据描述各条边:其中第 ii 行描述编号为 ii 的边——包含三个整数 aia_i、bib_i、cic_i(1 ≤ ai, bi ≤ n1 ≤ a_i, b_i ≤ n,0 ≤ ci ≤ 1090 ≤ c_i ≤ 10^9),分别表示该边的起点、终点及其初始权重。

接下来的 qq 行输入数据描述边的查询,格式同上(1 ≤ v ≤ n1 ≤ v ≤ n,1 ≤ lj ≤ m1 ≤ l_j ≤ m)。保证在单个查询中所有 ljl_j 互不相同。同时保证所有第二类查询中涉及的边的总数不超过 10610^6。

输出格式

For each query of first type print the length of the shortest path from 1 to v in a separate line. Print -1, if such path does not exists.

对于每个第一类查询,在单独一行中输出从节点 1 到节点 vv 的最短路径长度。如果这样的路径不存在,则输出 −1-1。

输入输出样例

  • 输入#1

    3 2 9
    1 2 0
    2 3 0
    2 1 2
    1 3
    1 2
    2 1 1
    1 3
    1 2
    2 2 1 2
    1 3
    1 2

    输出#1

    1
    0
    2
    1
    4
    2
  • 输入#2

    5 4 9
    2 3 1
    2 4 1
    3 4 1
    1 2 0
    1 5
    1 4
    2 1 2
    2 1 2
    1 4
    2 2 1 3
    1 4
    2 1 4
    1 4

    输出#2

    -1
    1
    2
    3
    4

说明/提示

The description of changes of the graph in the first sample case:

The description of changes of the graph in the second sample case:

第一个样例中图的变化描述:

第二个样例中图的变化描述:

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

首页