A11310 | Chat Screenshots
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ 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 $4$ participants in the chat, and their order is $[2, 3, 1, 4]$ . Then
- $1$ -st user sees the order $[1, 2, 3, 4]$ .
- $2$ -nd user sees the order $[2, 3, 1, 4]$ .
- $3$ -rd user sees the order $[3, 2, 1, 4]$ .
- $4$ -th user sees the order $[4, 2, 3, 1]$ .
$k$ 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.
For example, there are $4$ participants in the chat, and their order is $[2, 3, 1, 4]$ . Then
- $1$ -st user sees the order $[1, 2, 3, 4]$ .
- $2$ -nd user sees the order $[2, 3, 1, 4]$ .
- $3$ -rd user sees the order $[3, 2, 1, 4]$ .
- $4$ -th user sees the order $[4, 2, 3, 1]$ .
$k$ 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.
输入格式
The first line contains a single integer $t$ ( $1 \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 $n$ and $k$ ( $1 \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 $k$ lines contain descriptions of screenshots posted by the participants.
The $i$ -th row contains $n$ integers $a_{ij}$ each ( $1 \le a_{ij} \le n$ , all $a_{ij}$ are different) — the order of participants shown to the participant $a_{i0}$ , where $a_{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 \cdot k$ for all test cases does not exceed $2 \cdot 10^5$ . It is also guaranteed that all the authors of the screenshots are different.
The first line of the description of each test case contains two integers $n$ and $k$ ( $1 \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 $k$ lines contain descriptions of screenshots posted by the participants.
The $i$ -th row contains $n$ integers $a_{ij}$ each ( $1 \le a_{ij} \le n$ , all $a_{ij}$ are different) — the order of participants shown to the participant $a_{i0}$ , where $a_{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 \cdot k$ for all test cases does not exceed $2 \cdot 10^5$ . It is also guaranteed that all the authors of the screenshots are different.
输出格式
Output $t$ 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 $k$ 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.
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.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted