#P16918. [JLCPC 2026] 图

    ID: 19236 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>吉林O2优化2026省赛/邀请赛

[JLCPC 2026] 图

Problem Description

Given a simple, undirected, connected graph GG with nn vertices and mm edges. You need to choose two different edges to delete, obtaining a new graph G′G', and G′G' must remain connected.

Let the two deleted edges be (p,q)(p,q) and (u,v)(u,v). You need to minimize the sum of the shortest path length from pp to qq in G′G' and the shortest path length from uu to vv in G′G'. Output this minimum value, and also compute how many unordered edge-deletion plans can achieve this minimum.

Input Format

The first line contains an integer TT (1≤T≤50001 \le T \le 5000), the number of test cases. Then follow TT blocks, each describing one test case. For each test case:

  • The first line contains two integers n,mn, m (4≤n≤50004 \le n \le 5000, 5≤m≤50005 \le m \le 5000).
  • The next mm lines each contain two integers u,vu, v, representing an edge.

The constraints guarantee that ∑n,∑m≤5000\sum n, \sum m \le 5000. The given graph has no multiple edges and no self-loops, and there exists at least one way to delete edges such that the graph remains connected.

Output Format

For each test case, output one line containing two integers: the minimum value, and the number of unordered edge-deletion plans that achieve this minimum.

4
4 6
1 2
1 3
1 4
2 3
2 4
3 4
4 5
1 2
2 3
3 4
1 4
1 3
5 6
1 3
2 3
1 4
2 4
1 5
2 5
5 7
1 2
2 3
3 4
4 5
1 5
2 5
1 4
4 15
4 4
6 12
4 4

Hint

Translated by ChatGPT 5