Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
9
Indexable
Never
#include <iostream>

using namespace std;

int n,m;
int quanHe[110][110],F0[110],F1[110];
bool ngDaTiepXuc[110];

int main(){

	freopen("Text.txt","r",stdin);

	int tc;
	cin>>tc;
	for (int stc = 1; stc <= tc; stc++)
	{
		cout<<"#"<<stc;
		cin>>n>>m;
		//n la tong so nguoi
		//m la so ng la F0

		//nhap input mang quanHe
		for (int i = 1; i <= n ; i++)
		{
			ngDaTiepXuc[i] = false;
			for (int k = 1; k <= n; k++)
			{
				cin>>quanHe[i][k];
			}
		}

		//nhap vao F0
		for (int i = 1; i <= m; i++)
		{
			cin>>F0[i];
			ngDaTiepXuc[F0[i]] = true;
		}

		int soF1 = 0, soF2 = 0;

		//tinh so f1
		for (int i = 1; i <= m; i++)
		{
			int nguoiF0 = F0[i];
			for (int k = 1; k <= n; k++)
			{
				if (quanHe[nguoiF0][k] == 1 && ngDaTiepXuc[k] == false)
				{
					soF1++;
					F1[soF1] = k;
					ngDaTiepXuc[k] = true;
				}

			}
		}

		//tinh so f2
		for (int i = 1; i <= soF1; i++)
		{
			int nguoiF1 = F1[i];
			for (int k = 1; k <= n; k++)
			{
				if (quanHe[nguoiF1][k] == 1 && ngDaTiepXuc[k] == false)
				{
					soF2++;
					ngDaTiepXuc[k] = true;
				}
			}
		}

		cout<<" "<<soF1<<" "<<soF2<<endl;
	}

	return 0;
}