#P2153. [SDOI2009] 晨跑

    ID: 1131 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2009各省省选山东深度优先搜索,DFS费用流

[SDOI2009] 晨跑

Description

Elaxia has recently become obsessed with karate. He set up a fitness plan for himself, such as push-ups and sit-ups, but so far, the only thing he has stuck with is the morning run.

You are given a map of the area near the school, containing NN intersections and MM streets. Elaxia can only run from one intersection to another, and streets intersect only at intersections.

Every day, Elaxia runs from the dorm to the school. The dorm is numbered 11, and the school is numbered NN.

Elaxia’s morning runs follow a cycle (spanning several days). Because he dislikes repeating routes, within one cycle, the routes chosen on different days must not intersect at any intersection; the dorm and the school are not considered intersections.

Elaxia’s stamina is limited. He wants the total distance run in one cycle to be as short as possible, but he also wants the number of days in the training cycle to be as large as possible.

Besides practicing karate, Elaxia spends the rest of his time studying and looking for “MM” (meimei), so he asks you to design a morning running plan that meets his requirements.

There may exist an edge 1N1 \rightarrow N. In that case, this edge can be used at most once.

Input Format

The first line contains two integers N,MN, M, the number of intersections and streets.

The next MM lines each contain three integers a,b,ca, b, c, indicating there is a directed street from intersection aa to intersection bb with length cc.

Output Format

Output one line with two integers: the maximum number of days in a cycle, and, among all plans achieving this maximum, the minimal total distance.

7 10
1 2 1
1 3 1
2 4 1
3 4 1
4 5 1
4 6 1
2 5 5
3 6 6
5 7 1
6 7 1
2 11

Hint

  • For 30% of the testdata, N20N \le 20, M120M \le 120.
  • For 100% of the testdata, 2N2002 \leq N \le 200, 1M2×1041 \leq M \le 2 \times 10^4, 1c1041 \le c \le 10^4.

Translated by ChatGPT 5