Order Capital Round 1 (Codeforces Round 1038, Div. 1 + Div. 2)
D
Traffic Lights
Codeforces
2400
原题
← CE →
翻译中…

You are given a simple undirected connected graph of $n$ vertices and $m$ edges.

翻译中…

There is a token in vertex $1$. We consider the initial time to be at $0$ seconds. After $t$ seconds, if the token is in vertex $u$, you must do exactly one of the following:

翻译中…
  • wait one second,
  • move the token through the $(t \bmod \mathrm{deg}(u) + 1)$$^{\text{∗}}$-th edge of $u$, which takes one second.
翻译中…

The order of edges of a vertex is the order that they appear in the input.

翻译中…

Calculate the minimum time required to move the token from vertex $1$ to vertex $n$, and the minimum time spent waiting that can be achieved while minimizing the total time.

翻译中…

$^{\text{∗}}$$x \bmod y$ denotes the remainder from dividing $x$ by $y$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$, $m$ ($2 \leq n \leq 5000$, $n - 1 \leq m \leq \frac{n(n - 1)}{2}$) — the number of vertices and edges in the graph, respectively.

翻译中…

Then $m$ lines follow, the $i$-th line containing two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq n$) — the vertices of the $i$-th edge.

翻译中…

It is guaranteed that the graph is connected and simple.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $5000$, and the sum of $m$ over all test cases does not exceed $5\cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single line containing two integers — the minimum total time and the minimum waiting time that minimizes the total time, respectively.

翻译中…

Note

翻译中…

In the first test case, an optimal strategy is to do the following:

翻译中…
  • at time $0$, wait one second,
  • at time $1$, move the token from vertex $1$ to vertex $5$,
  • at time $2$, wait one second,
  • at time $3$, move the token from vertex $5$ to vertex $6$.
翻译中…

In the second test case, an optimal strategy is to do the following:

翻译中…
  • at time $0$, move the token from vertex $1$ to vertex $2$,
  • at time $1$, move the token from vertex $2$ to vertex $1$,
  • at time $2$, move the token from vertex $1$ to vertex $4$.
翻译中…

样例

Input #1
2
6 6
1 2
2 3
3 4
4 6
1 5
5 6
4 3
1 2
1 3
1 4
Output #1
4 2
3 0
InputCopy OutputCopy
题目信息
题号
2122D
时间限制
2 s
内存限制
256 MB
标签
暴力
数据结构
分治
动态规划
图论
贪心
最短路

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。