原题链接:http://210.44.14.31/problem/show/1088
本题数据太弱,只需判断结点的度符不符合条件即可。
欧拉路:
1.最多只能有两个点的入度与出度不相等。(这两个点出度大的必须作为起始点,入度大的必须作为终点。)
2.忽略边的方向后,图必须连通。
注意事项:
1.本题最后不需要换行。
2.判断点的度时别忘了 入度与出度不能同时为0 。
代码如下:
#include<iostream>
#include<cstdio>
using namespace std;
int InNodes[1000 + 5], OutNodes[1000 + 5];
int n, m;
bool oll()
{
int s = 0;
for (int i = 1; i <= n; i++)
{
if (InNodes[i] == 0 && OutNodes[i] == 0) return false; //入度与出度不能同时为0
if (InNodes[i] == OutNodes[i]) continue;
if (InNodes[i] + 1 == OutNodes[i] || InNodes[i] == OutNodes[i] + 1) s++; //记录入度与出度不相等的点的数量
else return false; //入度与出度相差2或大于的 直接false
if (s > 2) //超过2个结点的 直接false
return false;
}
return true;
}
int main()
{
int u, v;
cin >> n >> m;
while (m--)
{
cin >> u >> v;
InNodes[v]++;
OutNodes[u]++;
}
if (oll())
cout << "YES" ;
else cout << "NO" ;
return 0;
}