传统题 1000ms 256MiB

Elden Ring I——艾尔登法环 I

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Statement

Timothy has recently become obsessed with a Souls-like game called Elden Ring. The goal is simple: level up, defeat monsters, and ultimately defeat the boss.

Although it's an open world, because the game's director, Hidetaka Miyazaki, likes small-scale maps, one-way doors often appear. These doors require the player to open them in order to connect two locations. For example, a one-way door from A to B cannot be opened from B. Before the door is opened, you can't go from B to A. You need to take another route to A to open the one-way door, and then you can go from B to A. On a normal path, A and B are mutually accessible.

At the beginning of the game, the player is teleported to a node called "Grace." The player can teleport back to "Grace" at any time. The player's goal is to reach a node called "Boss" to defeat the boss. Assume that the distance from one node to the adjacent node is 1. You need to calculate the shortest path from "Grace" to the boss. If the player teleports back to "Grace" or passes through "Grace" again, the path calculation must be restarted.

Input

The first line contains an integer n(2n104)n(2\leq n\leq 10^4), representing the number of nodes, where each node is numbered 1,2,3,,n1,2,3,\cdots,n;

The second line contains two integers a,b(1a,bn)a,b (1\leq a,b\leq n), representing the number of "Grace" points aa and the number of boss points bb;

The third line contains two integers c,dc,d, representing the number of one-way doors cc and the number of normal roads dd;

The next cc lines, each containing two integers ti,tjt_i,t_j, indicate that the door from node tit_i to tjt_j is a one-way door, and that it is impossible to go from tjt_j to tit_i until it is opened;

The next dd lines, each containing two integers ri,rjr_i,r_j, indicate the number of one-way doors from node tit_i to tjt_j. The path from rir_i to rjr_j is a normal path, and nodes rir_i and sjs_j are connected.

Output

Output an integer representing the shortest distance from the "Grace" point to the Boss point.

If the boss point can never be reached, output false

Samples

10
1 10
1 8
4 2
1 2
2 3
3 5
5 6
6 7
7 4
4 10
8 9
3

Notes

For the example shown below, the player can open the one-way door in the following order: $1\rightarrow 2\rightarrow 3\rightarrow 5\rightarrow 6\rightarrow 7\rightarrow 4\rightarrow 2$, then teleport back to the blessing 124101\rightarrow 2\rightarrow 4\rightarrow 10. The distance of 3 is the shortest path.

2025 JSUT Collegiate Programming Contest 江苏理工学院新生赛-同步赛

未参加
状态
已结束
规则
ACM/ICPC
题目
15
开始于
2025-11-8 12:00
结束于
2025-11-8 17:00
持续时间
5 小时
主持人
参赛人数
15