CF1391E.Pairs of Pairs

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have a simple and connected undirected graph consisting of nn nodes and mm edges.

Consider any way to pair some subset of these nn nodes such that no node is present in more than one pair.

This pairing is valid if for every pair of pairs, the induced subgraph containing all 44 nodes, two from each pair, has at most 22 edges (out of the 66 possible edges). More formally, for any two pairs, (a,b)(a,b) and (c,d)(c,d), the induced subgraph with nodes a,b,c,d{a,b,c,d} should have at most 22 edges.

Please note that the subgraph induced by a set of nodes contains nodes only from this set and edges which have both of its end points in this set.

Now, do one of the following:

  • Find a simple path consisting of at least ⌈n2⌉\lceil \frac{n}{2} \rceil nodes. Here, a path is called simple if it does not visit any node multiple times.
  • Find a valid pairing in which at least ⌈n2⌉\lceil \frac{n}{2} \rceil nodes are paired.

It can be shown that it is possible to find at least one of the two in every graph satisfying constraints from the statement.

你有一个由 nn 个节点和 mm 条边组成的简单且连通的无向图。

考虑任意一种方式,从这 nn 个节点中选取某个子集,并将其中节点两两配对,使得每个节点至多出现在一个配对中。

若对任意两个配对 (a,b)(a,b) 和 (c,d)(c,d),由节点集合 {a,b,c,d}\{a,b,c,d\} 所诱导的子图中至多包含 22 条边(共 66 种可能的边),则该配对称为合法的。更严格地说,对于任意两个配对 (a,b)(a,b) 和 (c,d)(c,d),由节点 {a,b,c,d}\{a,b,c,d\} 诱导的子图应至多含 22 条边。

请注意:一个节点集合所诱导的子图仅包含该集合中的节点,以及两个端点均属于该集合的所有边。

现在,请完成以下二者之一:

  • 找出一条至少包含 ⌈n2⌉\lceil \frac{n}{2} \rceil 个节点的简单路径(即不重复经过任一节点的路径);
  • 找出一个合法的配对,其中至少有 ⌈n2⌉\lceil \frac{n}{2} \rceil 个节点被配对。

可以证明:对于满足题目约束条件的任意图,上述两种方案中至少有一种总能实现。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1051 \le t \le 10^5). Description of the test cases follows.

The first line of each test case contains 22 integers n,mn, m (2≤n≤5⋅1052 \le n \le 5\cdot 10^5, 1≤m≤1061 \le m \le 10^6), denoting the number of nodes and edges, respectively.

The next mm lines each contain 22 integers uu and vv (1≤u,v≤n1 \le u, v \le n, u≠vu \neq v), denoting that there is an undirected edge between nodes uu and vv in the given graph.

It is guaranteed that the given graph is connected, and simple — it does not contain multiple edges between the same pair of nodes, nor does it have any self-loops.

It is guaranteed that the sum of nn over all test cases does not exceed 5⋅1055\cdot 10^5.

It is guaranteed that the sum of mm over all test cases does not exceed 10610^6.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1051 \le t \le 10^5)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 n,mn, m(2≤n≤5⋅1052 \le n \le 5\cdot 10^5,1≤m≤1061 \le m \le 10^6),分别表示图中节点数和边数。

接下来的 mm 行,每行包含两个整数 uu 和 vv(1≤u,v≤n1 \le u, v \le n,u≠vu \neq v),表示图中节点 uu 与节点 vv 之间存在一条无向边。

保证所给图是连通的,且是简单图——即任意一对节点间至多只有一条边,且不存在自环。

保证所有测试用例的 nn 之和不超过 5⋅1055\cdot 10^5。

保证所有测试用例的 mm 之和不超过 10610^6。

输出格式

For each test case, the output format is as follows.

If you have found a pairing, in the first line output "PAIRING" (without quotes).

  • Then, output kk (⌈n2⌉≤2⋅k≤n\lceil \frac{n}{2} \rceil \le 2\cdot k \le n), the number of pairs in your pairing.
  • Then, in each of the next kk lines, output 22 integers aa and bb — denoting that aa and bb are paired with each other. Note that the graph does not have to have an edge between aa and bb!
  • This pairing has to be valid, and every node has to be a part of at most 11 pair.

Otherwise, in the first line output "PATH" (without quotes).

  • Then, output kk (⌈n2⌉≤k≤n\lceil \frac{n}{2} \rceil \le k \le n), the number of nodes in your path.
  • Then, in the second line, output kk integers, v1,v2,…,vkv_1, v_2, \ldots, v_k, in the order in which they appear on the path. Formally, viv_i and vi+1v_{i+1} should have an edge between them for every ii (1≤i<k1 \le i \lt k).
  • This path has to be simple, meaning no node should appear more than once.

对于每个测试用例,输出格式如下:

若你找到了一个配对方案,则在第一行输出 "PAIRING"(不带引号)。

  • 接着,输出 kk(满足 ⌈n2⌉≤2⋅k≤n\lceil \frac{n}{2} \rceil \le 2\cdot k \le n),表示你所构造的配对方案中包含的配对数量;
  • 然后,在接下来的 kk 行中,每行输出两个整数 aa 和 bb,表示 aa 与 bb 相互配对。注意:图中 不一定 存在连接 aa 和 bb 的边!
  • 该配对方案必须合法,且每个节点至多属于一个配对。

否则(即未找到配对方案),在第一行输出 "PATH"(不带引号)。

  • 接着,输出 kk(满足 ⌈n2⌉≤k≤n\lceil \frac{n}{2} \rceil \le k \le n),表示你所构造的路径中包含的节点数量;
  • 然后,在第二行输出 kk 个整数 v1,v2,…,vkv_1, v_2, \ldots, v_k,按它们在路径中出现的顺序排列。形式化地,对每个 ii(1≤i<k1 \le i \lt k),viv_i 与 vi+1v_{i+1} 之间必须存在一条边;
  • 该路径必须是简单路径,即任意节点至多出现一次。

输入输出样例

  • 输入#1

    4
    6 5
    1 4
    2 5
    3 6
    1 5
    3 5
    6 5
    1 4
    2 5
    3 6
    1 5
    3 5
    12 14
    1 2
    2 3
    3 4
    4 1
    1 5
    1 12
    2 6
    2 7
    3 8
    3 9
    4 10
    4 11
    2 4
    1 3
    12 14
    1 2
    2 3
    3 4
    4 1
    1 5
    1 12
    2 6
    2 7
    3 8
    3 9
    4 10
    4 11
    2 4
    1 3

    输出#1

    PATH
    4 
    1 5 3 6
    PAIRING
    2
    1 6
    2 4
    PAIRING
    3
    1 8
    2 5
    4 10
    PAIRING
    4
    1 7
    2 9
    3 11
    4 5

说明/提示

The path outputted in the first case is the following.

The pairing outputted in the second case is the following.

Here is an invalid pairing for the same graph — the subgraph 1,3,4,5{1,3,4,5} has 33 edges.

Here is the pairing outputted in the third case.

It's valid because —

  • The subgraph 1,8,2,5{1,8,2,5} has edges (11,22) and (11,55).
  • The subgraph 1,8,4,10{1,8,4,10} has edges (11,44) and (44,1010).
  • The subgraph 4,10,2,5{4,10,2,5} has edges (22,44) and (44,1010).

Here is the pairing outputted in the fourth case.

第一种情况输出的路径如下所示。

第二种情况输出的配对如下所示。

以下是同一图的一个无效配对——子图 1,3,4,5{1,3,4,5} 包含 33 条边。

第三种情况输出的配对如下所示。

该配对是有效的,因为——

  • 子图 1,8,2,5{1,8,2,5} 包含边 (1,2)(1,2) 和 (1,5)(1,5);
  • 子图 1,8,4,10{1,8,4,10} 包含边 (1,4)(1,4) 和 (4,10)(4,10);
  • 子图 4,10,2,5{4,10,2,5} 包含边 (2,4)(2,4) 和 (4,10)(4,10)。

第四种情况输出的配对如下所示。

输入解题思路,AI测评打分。不知道怎么写?

首页