当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5807:Keep In Touch

题目描述
There are $n$ cities numbered with successive integers from $1$ to $n$ in Byteland. Also, there are $m$ one-way roads connecting the cities. The starting point of the $i$-th road is $u_i$ while the ending point is $v_i$.

There are $3$ spies : 007, 008 and 009. They are going to start $q$ secret missions.

During each mission, they may be in three different cities, and they contact each other using interphones. The radio frequency of the $i$-th city is $w_i$. Two spies can contact with each other if and only if the absolute value of the difference of radio frequency between the cities where they are in is no more than $K$. At each moment, three spies must choose a road and go to another city. The time for traveling each road is only a unit of time.

They can choose to end the mission in any city, even in the city where they started the mission. But they are not allowed to end mission in the middle of the roads. Now they want to know, for each mission whose start points are given, what's the number of possible ways, during which they can contact with each other at any moment when they are not on roads?

Two ways are considered different if and only if there exists at least one spy at different cities on the same moment.

Note : $3$ spies must end the mission at the same time.
输入解释
The first line of the input contains an integer $T$ $(1\leq T\leq 10)$, denoting the number of test cases.

In each test case, the first line of the input contains four integers $n$ $(1\leq n\leq 50),m(0\leq m\leq \frac{n(n-1)}{2}),K(0\leq K\leq 10^9),q(1\leq q\leq 125000)$, denoting the number of cities, the number of roads, the upper limit of interphone and the number of missions.

The second line of the input contains $n$ integers $w_1, w_2, ..., w_n$ $(1\leq w_i\leq 10^9)$, denoting the radio frequency of the $i$-th city.

Each of the next $m$ lines contains two integers $u_i,v_i$ $(1\leq u_i < v_i\leq n)$, denoting an one-way road. There are no multiple edges in the graph.

Each of the next $q$ lines contains three integers $x,y,z(1\leq x,y,z\leq n)$, denoting the starting point of the three spies in each mission. You can assume that there are at least one possible way in each mission.
输出解释
For each test case, print $q$ lines with one integer per line. For each mission, print the number of possible ways modulo $998244353$.
输入样例
1
4 4 2 10
8 8 4 1
1 3
1 4
2 3
2 4
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2
3 3 3
4 4 4
输出样例
3
3
3
3
3
3
3
3
1
1
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #86

源链接: HDU-5807

最后修改于 2020-10-25T23:25:48+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 262144/131072K(Java/Others)