CF1931F.Chat Screenshots

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn people in the programming contest chat. Chat participants are ordered by activity, but each person sees himself at the top of the list.

For example, there are 44 participants in the chat, and their order is [2,3,1,4][2, 3, 1, 4]. Then

  • 11-st user sees the order [1,2,3,4][1, 2, 3, 4].
  • 22-nd user sees the order [2,3,1,4][2, 3, 1, 4].
  • 33-rd user sees the order [3,2,1,4][3, 2, 1, 4].
  • 44-th user sees the order [4,2,3,1][4, 2, 3, 1].

kk people posted screenshots in the chat, which show the order of participants shown to this user. The screenshots were taken within a short period of time, and the order of participants has not changed.

Your task is to determine whether there is a certain order that all screenshots correspond to.

编程竞赛聊天室中有 nn 个人。聊天参与者按活跃度排序,但每个人在自己看到的列表中都位于顶部。

例如,聊天室中有 44 名参与者,其实际顺序为 [2,3,1,4][2, 3, 1, 4]。那么:

  • 第 11 位用户看到的顺序为 [1,2,3,4][1, 2, 3, 4]。
  • 第 22 位用户看到的顺序为 [2,3,1,4][2, 3, 1, 4]。
  • 第 33 位用户看到的顺序为 [3,2,1,4][3, 2, 1, 4]。
  • 第 44 位用户看到的顺序为 [4,2,3,1][4, 2, 3, 1]。

共有 kk 人发布了截图到聊天室中,每张截图显示了该用户所看到的参与者顺序。这些截图是在很短的时间内拍摄的,期间参与者的实际顺序未发生变化。

你的任务是判断是否存在某个确定的实际顺序,使得所有截图均与之相符。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of input test cases. The descriptions of test cases follow.

The first line of the description of each test case contains two integers nn and kk (1≤k≤n≤2⋅105,n⋅k≤2⋅1051 \le k \le n \le 2 \cdot 10^5, n \cdot k \le 2 \cdot 10^5) — the number of chat participants and the number of participants who posted screenshots.

The following kk lines contain descriptions of screenshots posted by the participants.

The ii-th row contains nn integers aija_{ij} each (1≤aij≤n1 \le a_{ij} \le n, all aija_{ij} are different) — the order of participants shown to the participant ai0a_{i0}, where ai0a_{i0} — the author of the screenshot. You can show that in the screenshot description it will always be at the top of the list.

It is guaranteed that the sum of n⋅kn \cdot k for all test cases does not exceed 2⋅1052 \cdot 10^5. It is also guaranteed that all the authors of the screenshots are different.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 输入测试用例的数量。随后是各测试用例的描述。

每个测试用例的描述的第一行包含两个整数 nn 和 kk(1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5,且 n⋅k≤2⋅105n \cdot k \le 2 \cdot 10^5)—— 分别表示聊天参与者总数和发布截图的参与者人数。

接下来的 kk 行描述了各参与者发布的截图。

第 ii 行包含 nn 个整数 aija_{ij}(1≤aij≤n1 \le a_{ij} \le n,且所有 aija_{ij} 互不相同)—— 表示在参与者 ai0a_{i0} 所见的截图中,各参与者的显示顺序,其中 ai0a_{i0} 为该截图的作者。可以证明:在截图描述中,作者始终位于列表最上方。

保证所有测试用例的 n⋅kn \cdot k 之和不超过 2⋅1052 \cdot 10^5。同时保证所有截图作者互不相同。

输出格式

Output tt lines, each of which is the answer to the corresponding test case. As an answer, output "YES" if there exists at least one order of participants, under which all kk screenshots could have been obtained. Otherwise, output "NO".

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

输出 tt 行,每行对应一个测试用例的答案。若存在至少一种参赛者排名顺序,使得所有 kk 张截图均可能被获取,则输出 "YES";否则输出 "NO"。

答案的大小写不限(例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均被视为肯定回答)。

输入输出样例

  • 输入#1

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

    输出#1

    YES
    YES
    YES
    YES
    NO
    YES
    YES
    YES
    YES
    NO

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

首页