题目收集
题目列表题单
返回列表

Hunting for Treasure

CodeforcesP0036· 1000ms· 1024 MB· ZJU Summer 2026 Contest 3原题链接
网络流二分图

创建于 2026/07/16 · 更新于 2026/07/16

题目描述

You're playing a game.

The game consists of nnn boss battles, indexed 1…n1\dots n1…n. The battles can be completed in any order, but any battle can only be completed once. There are mmm possible rewards for completing a battle, indexed 1…m1\dots m1…m. However, not all rewards can be obtained by completing any battle. For each battle iii, there is a list of possible rewards Ai=[ai1,ai2…aik]A_i = [a_{i1},a_{i2} \dots a_{ik}]Ai​=[ai1​,ai2​…aik​]. You can only get rewards in AiA_{i}Ai​ after you have completed battle iii.Additionally, once you have obtained a given reward, you cannot obtain it again.

When you complete battle iii, you will receive one of rewards from AiA_iAi​ that you have not yet received, at random. If you have already obtained all possible rewards from battle iii, you get nothing.

You want to find out which rewards you can guarantee obtaining. Your task is to, for each i=1…mi= 1\dots mi=1…m independently, find out if there is a strategy that guarantees you will receive reward iii.

输入格式

The first line contains one integer ttt (1≤t≤1000)(1 \le t \le 1000)(1≤t≤1000) —the number of test cases. Each test case is described as follows.

The first line contains two integers nnn and mmm (1≤n,m≤250)(1 \le n, m \le 250)(1≤n,m≤250) — the number of battles and rewards,respectively.

The next nnn lines describe the possible rewards for completing battles.

The iii-th line starts with an integer kik_iki​ (0≤ki≤m)(0 \le k_i \le m)(0≤ki​≤m),followed by kik_iki​ integers ai1,ai2,…,aikia_{i1}, a_{i2}, \ldots, a_{ik_i}ai1​,ai2​,…,aiki​​ (1≤ai1<ai2<⋯<aiki≤m)(1 \le a_{i1} \lt a_{i2} \lt \cdots \lt a_{ik_i} \le m)(1≤ai1​<ai2​<⋯<aiki​​≤m) —the possible rewards for completing battle iii.

It is guaranteed that the sum of ∑i=1nki\sum_{i=1}^{n} k_i∑i=1n​ki​ over all test cases doesn't exceed 10510^5105.

输出格式

For each test case, print a binary string of length mmm. The iii-th character should be 1 if it is possible to guarantee obtaining reward iii, and 0 otherwise.

样例输入 #1

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

样例输出 #1

1110
01011