diamondquoc

 avatar
quoc14
c_cpp
5 months ago
1.1 kB
3
Indexable
caidat
#include <iostream>

using namespace std;

int a[1005][1005];
int kt[1005];
int vs[1005];
int dem[1005];
int check;

void memm(int n)
{
	for (int i=1; i<=n; i++)
	{
		vs[i] = 0;
		for (int j=1; j<=n; j++)
			{
				a[i][j] = 0;
			}
	}
}

void DFS(int i, int n)
{
	vs[i] = 1;
	kt[i] = 1;dem[i] += 1;
	if (dem[i] >= 2)
		check = 1;
	
	for (int j=1; j<=n; j++)
	{
		if (check == 1) break;
		if (a[i][j] == 1 && kt[j] == 0)
			DFS(j,n);
	}
	kt[i] = 0;
}

void memm1(int n)
{
	for (int i=1; i<=n; i++)
	{
		kt[i] = 0;
		dem[i] = 0;
	}
}

int main()
{
	//freopen("input.txt","r",stdin);
	int ntc;
	int n;
	cin >> ntc;
	for (int tc=1; tc<=ntc; tc++)
	{
		cin >> n;
		memm(n);
		for (int i = 1; i<= n; i++)
		{
			int tmp;
			cin >> tmp;
			for (int j = 1; j<=tmp; j++)
			{
				int tmp1;
				cin >> tmp1;
				a[i][tmp1] = 1;
			}
		}

		check = false;

		for (int i = 1; i<=n; i++)
		if (vs[i] == 0)
		{
			memm1(n);
			DFS(i,n);
			if (check == 1)
			break;
		}

		int n;
		cout<<"Case #"<<tc<<endl<< (check  == 1 ? "Yes" : "No" )<<endl;
	}

	return 0;
}
Leave a Comment