1568_Connectivity

2022-5-16 18:17| 发布者: Hocassian| 查看: 49| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-2-89503979518500-Problem List-采集的数据-后羿采集器.html

Pro.ID

1568

Title

Connectivity

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=1568

AC

25

Submit

60

Ratio

41.67%

时间&空间限制

  • Time Limit: 20000/10000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others)
  • 描述

    Given an undirected graph G = (V, E), and two vertices u, vV, you are asked to determine whether there is a path between u and v.

    输入

    The input begins with a line containing an integer T (T ≤ 500), which indicates the number of test cases. Each case begins with four integers N, M, u and v (2 ≤ N ≤ 10000, 0 ≤ M ≤ 100000, 1 ≤ u, vN, uv). The following M lines each consist of two integers a and b (1 ≤ a, bN, ab), indicating that edge (a, b) ∈ E.

    输出

    Description

    Given an undirected graph G = (V, E), and two vertices u, vV, you are asked to determine whether there is a path between u and v.

    Input

    The input begins with a line containing an integer T (T ≤ 500), which indicates the number of test cases. Each case begins with four integers N, M, u and v (2 ≤ N ≤ 10000, 0 ≤ M ≤ 100000, 1 ≤ u, vN, uv). The following M lines each consist of two integers a and b (1 ≤ a, bN, ab), indicating that edge (a, b) ∈ E.

    Output

    For each case, output YES if there is a path between a and b; otherwise output NO .

    Sample Input

    2
    4 4 1 2
    1 3
    3 4
    4 2
    2 3
    6 6 3 4
    1 2
    2 3
    1 3
    4 5
    5 6
    4 6

    Sample Output

    YES
    NO

    Author

    样例输入

    2
    4 4 1 2
    1 3
    3 4
    4 2
    2 3
    6 6 3 4
    1 2
    2 3
    1 3
    4 5
    5 6
    4 6

    样例输出

    YES
    NO

    提示

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部