CF B. Gardener and the Array

B. Gardener and the Array

思路:只要找到一个c他的每一位均在除了它的集合中出现过即可

这题T了2发,用来multiset,注意multiset大的时间复杂度是O(K + logn)k是相同元素的个数,能用map尽量用map

#include <bits/stdc++.h> 

using namespace std;

const int N = 1e5 + 10;

void solve()
{
	int n; scanf("%d", &n);
	vector<int>a[n + 1];
	map<int, int>cnt;
 	for(int i = 1; i <= n; ++ i)
 	{
  		int k;
  		scanf("%d", &k);
  		a[i].push_back(k);
	  	for(int j = 0; j < k; ++ j)
	  	{
	   		int x; scanf("%d", &x);
	   		a[i].push_back(x);
	   		cnt[x] ++;
	  	}
	}
	
	for(int i = 1; i <= n; ++ i)
	{
		int k = a[i][0];
		for(int j = 1; j <= k; ++ j) 
		{
			if(cnt[a[i][j]] < 2) break; 
			if(j == k && cnt[a[i][j]] >= 2)
			{
				printf("Yes\n");
			    return;
			}
		}
	}
	printf("No\n");
}

int main()
{
//	freopen("1.in", "r", stdin);
	int t; scanf("%d", &t);
	while(t --) solve();
	return 0;
}
posted @   cxy8  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
点击右上角即可分享
微信分享提示