#P9235. [蓝桥杯 2023 省 A] 网络稳定性

    ID: 10407 远端评测题 1500ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>图论贪心并查集2023生成树最近公共祖先 LCA蓝桥杯省赛

[蓝桥杯 2023 省 A] 网络稳定性

Problem Description

There is a local area network consisting of nn devices and mm physical connections. The stability of the ii-th connection is wiw_i.

For a path from device AA to device BB that passes through several physical connections, we define the stability of this path as the minimum stability among all connections on the path.

We define the communication stability between device AA and device BB as the maximum stability among all feasible paths from AA to BB.

Given the physical connection information in the LAN, compute the communication stability for several pairs of devices xix_i and yiy_i. If there is no path between two devices, output 1-1.

Input Format

The first line contains three integers n,m,qn, m, q, representing the number of devices, the number of physical connections, and the number of queries.

The next mm lines each contain three integers ui,vi,wiu_i, v_i, w_i, meaning there is a physical connection between uiu_i and viv_i with stability wiw_i.

The next qq lines each contain two integers xi,yix_i, y_i, asking for the communication stability between xix_i and yiy_i.

Output Format

Output qq lines. Each line contains one integer, in order, representing the answer to each query.

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

Hint

[Scale and constraints of testdata]

For 30%30\% of the testdata, n,q500n, q \leq 500, m1000m \leq 1000.

For 60%60\% of the testdata, n,q5000n, q \leq 5000, m10000m \leq 10000.

For all testdata, 2n,q1052 \leq n, q \leq 10^5, 1m3×1051 \leq m \leq 3 \times 10^5, 1ui,vi,xi,yin1 \leq u_i, v_i, x_i, y_i \leq n, 1wi1061 \leq w_i \leq 10^6, uiviu_i \neq v_i, xiyix_i \neq y_i.

Translated by ChatGPT 5