帮忙找个茬..

#include <bits/stdc++.h>
using namespace std;

vector<int> v[200010];
int t, n, m, cnt, flag, indegree[200010];
bool vis[200010];
void dfs(int x)
{
	++cnt;
	vis[x] = 1;
	for (int i = 0; i < v[x].size(); ++i)
	{
		if (vis[v[x][i]] == 0)
		{
			dfs(v[x][i]);
		}
	}
}

int main()
{
	cin >> t;
	for (int k = 1; k <= t; ++k)
	{
		cnt = 0;
		flag = 0;
		memset(vis, 0, sizeof(vis));
		memset(indegree, 0, sizeof(indegree));
		for (int i = 1; i <= n; ++i)
		{
			v[i].clear();
		}
		cin >> n >> m;
	for (int i = 1; i <= m; ++i)
	{
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		indegree[y]++;
		if (indegree[y] >= 2) flag = 1;
	}
	if (n != m + 1) flag = 1;
	for (int i = 1; i <= n; ++i)
	{
		if (indegree[i] == 0) 
		{
			dfs(i);
			break;
		}
	}
	if (cnt != n) flag = 1;
	if (flag == 1) cout << "Case " << k << " is not a tree.\n";
	else cout << "Case " << k << "is a tree.\n";
}
	}
	
1 个赞

发帖的时候把格式调好一点 :smiling_face_with_tear:,不然截个图也可以

OK

@信友队蔡老师 尽力了

@AnteAntibe_LHP
救命

没加空格。

哦,谢啦

1 个赞