F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Shortest Path

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2022    Accepted Submission(s): 673


Problem Description
There is a path graph $G=(V,E)$ with $n$ vertices. Vertices are numbered from $1$ to $n$ and there is an edge with unit length between $i$ and $i + 1$ $(1 \le i < n)$. To make the graph more interesting, someone adds three more edges to the graph. The length of each new edge is $1$.

You are given the graph and several queries about the shortest path between some pairs of vertices.
 

Input
There are multiple test cases. The first line of input contains an integer $T$, indicating the number of test cases. For each test case:

The first line contains two integer $n$ and $m$ $(1 \le n, m \le 10^5)$ -- the number of vertices and the number of queries. The next line contains 6 integers $a_1, b_1, a_2, b_2, a_3, b_3$ $(1 \le a_1,a_2,a_3,b_1,b_2,b_3 \le n)$, separated by a space, denoting the new added three edges are $(a_1,b_1)$, $(a_2,b_2)$, $(a_3,b_3)$.

In the next $m$ lines, each contains two integers $s_i$ and $t_i$ $(1 \le s_i, t_i \le n)$, denoting a query.

The sum of values of $m$ in all test cases doesn't exceed $10^6$.
 

Output
For each test cases, output an integer $S=(\displaystyle\sum_{i=1}^{m} i \cdot z_i) \text{ mod } (10^9 + 7)$, where $z_i$ is the answer for $i$-th query.
 

Sample Input
1 10 2 2 4 5 7 8 10 1 5 3 1
 

Sample Output
7
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-03-29 13:18:46, Gzip enabled