| Codeforces Round 1077 (Div. 1) |
|---|
| Finished |
Jerry and Tom are playing a game on a directed graph $$$G$$$ with $$$n$$$ vertices, numbered from $$$1$$$ to $$$n$$$. For every vertex $$$1 \le u \lt n$$$, there is a directed edge from $$$u$$$ to $$$u+1$$$. In addition, there are $$$m$$$ extra directed edges. The $$$i$$$-th extra edge goes from $$$u_i$$$ to $$$v_i$$$, where $$$1 \le u_i \lt v_i \le n$$$.
The graph $$$G$$$ has the following special property: there do not exist two directed edges $$$(u_i\to v_i)$$$ and $$$(u_j\to v_j)$$$ such that $$$u_i \lt u_j \lt v_i \lt v_j$$$.
At the beginning of the game, Jerry and Tom stand on vertices $$$x$$$ and $$$y$$$, respectively, where $$$x \ne y$$$. The game proceeds in turns. In each turn, the players behave according to the following rules, with Jerry going first, followed by Tom:
If at the end of any turn, Jerry and Tom are at the same vertex (including at vertex $$$n$$$), the game ends immediately and Tom wins. Otherwise, if Jerry is initially at vertex $$$n$$$, or reaches vertex $$$n$$$ at the end of any turn, Jerry wins.
Note that if after a turn, both Jerry and Tom are at vertex $$$n$$$, then Tom wins.
Throughout the entire game, both players know each others' locations.
It can be proven that the game will end in a finite number of turns.
For a pair of integers $$$1 \le x,y \le n$$$, $$$x \ne y$$$, define $$$f(x,y)$$$ as follows:
Compute $$$$$$\sum\limits_{1 \le x,y \le n, x \ne y}f(x,y).$$$$$$
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le n-2$$$), representing the number of vertices and the number of extra edges, respectively.
The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i,v_i \le n$$$, $$$u_i + 1 \lt v_i$$$), representing an extra edge. It is guaranteed that for any ordered pair of vertices $$$(u,v)$$$, there exists at most one edge from $$$u$$$ to $$$v$$$. It is guaranteed that there do not exist two directed edges $$$(u_i\to v_i)$$$ and $$$(u_j\to v_j)$$$ such that $$$u_i \lt u_j \lt v_i \lt v_j$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output an integer representing the value of the expression.
52 03 11 34 22 41 45 11 48 31 45 82 4
026323
In the first test case:
In the third test case, the pairs of $$$(x,y)$$$ such that Tom wins are as follows:
| Name |
|---|


