CF960F.Pathwalks

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a directed graph with n nodes and m edges, with all edges having a certain weight.

There might be multiple edges and self loops, and the graph can also be disconnected.

You need to choose a path (possibly passing through same vertices multiple times) in the graph such that the weights of the edges are in strictly increasing order, and these edges come in the order of input. Among all such paths, you need to find the the path that has the maximum possible number of edges, and report this value.

Please note that the edges picked don't have to be consecutive in the input.

给你一个包含 nn 个节点和 mm 条边的有向图,每条边具有一定的权重。

图中可能存在重边和自环,且该图也可能是不连通的。

你需要在图中选择一条路径(允许重复经过同一顶点),使得所选边的权重严格递增,且这些边在输入中的出现顺序与所选顺序一致。在所有满足条件的路径中,你需要找出边数最多的那条路径,并输出该最大边数。

请注意:所选的边在输入中不必连续出现。

输入格式

The first line contains two integers n and m (1 ≤ n ≤ 100000,1 ≤ m ≤ 100000) — the number of vertices and edges in the graph, respectively.

m lines follows.

The i-th of these lines contains three space separated integers a__i, b__i and w__i (1 ≤ a__i, b__i ≤ n, 0 ≤ w__i ≤ 100000), denoting an edge from vertex a__i to vertex b__i having weight w__i

第一行包含两个整数 nn 和 mm(1 ≤ n ≤ 1000001 ≤ n ≤ 100000,1 ≤ m ≤ 1000001 ≤ m ≤ 100000),分别表示图中顶点和边的数量。

接下来有 mm 行。

第 ii 行包含三个以空格分隔的整数 aia_i、bib_i 和 wiw_i(1 ≤ ai, bi ≤ n1 ≤ a_i, b_i ≤ n,0 ≤ wi ≤ 1000000 ≤ w_i ≤ 100000),表示一条从顶点 aia_i 指向顶点 bib_i、权重为 wiw_i 的有向边。

输出格式

Print one integer in a single line — the maximum number of edges in the path.

在一行中输出一个整数——该路径中边的最大数量。

输入输出样例

  • 输入#1

    3 3
    3 1 3
    1 2 1
    2 3 2

    输出#1

    2
  • 输入#2

    5 5
    1 3 2
    3 2 3
    3 4 5
    5 4 0
    4 5 8

    输出#2

    3

说明/提示

The answer for the first sample input is 2: . Note that you cannot traverse because edge appears earlier in the input than the other two edges and hence cannot be picked/traversed after either of the other two edges.

In the second sample, it's optimal to pick 1-st, 3-rd and 5-th edges to get the optimal answer: .

第一个样例输入的答案是 2:。注意,你不能遍历 ,因为边 在输入中出现得比另外两条边更早,因此无法在另外两条边中的任意一条之后被选取/遍历。

在第二个样例中,最优策略是选取第 1、第 3 和第 5 条边,从而得到最优答案:。

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

首页