luogu#P2169. 正则表达式

正则表达式

Background

One day, student Xiao Z unexpectedly saw Xiao X write an advanced regular expression program. This regex is composed only of the characters "0", "1", ".", and "*", yet it can match the core code of all programs that get AC on the OJ! Xiao Z became very curious, so he decided to hack into Xiao X's computer to obtain this advanced regex program.

Problem Description

In the Internet, computers are not directly connected one-to-one. Instead, some computers have one-way network connections. That is, even if there is a connection from AA to BB, there may not be a connection from BB to AA. Moreover, some connections are fast while others are slow, so the transmission time differs across connections. In addition, if both the connection from AA to BB and the connection from BB to AA exist, then AA and BB are effectively in the same LAN and can communicate locally, with a transmission time of 00.

Now Xiao Z gives you the topology of the network. He wants to know the shortest transmission time from his computer (numbered 11) to Xiao X's computer (numbered nn).

Input Format

The first line contains two integers n,mn, m, meaning there are nn computers and mm connections.

The next mm lines each contain three integers u,v,wu, v, w, meaning the time to transmit information from computer uu to computer vv is ww.

Output Format

Output a single line with the shortest transmission time.

3 2
1 2 1
2 3 1

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

3

Hint

  • For 40%40\% of the data, 1n1031 \leq n \leq 10^3, 1m1041 \leq m \leq 10^4.
  • For 70%70\% of the data, 1n5×1031 \leq n \leq 5 \times 10^3, 1m1051 \leq m \leq 10^5.
  • For 100%100\% of the data, 1n2×1051 \leq n \leq 2 \times 10^5, 1m1061 \leq m \leq 10^6.

The answer is guaranteed to fit in the int range.

Translated by ChatGPT 5