又是猜的..但是看了题解,有一些地方还是可以的.
是否存在一棵树,满足所有边都被走过偶数次.
给出所有需要走的路的头尾.
这题关键在于,树上两点想要走通,一种是不走根,直接互联(当然有的只能走根),第二种是走根(当然在很多时候这是浪费的),我们只关心奇偶性的情况下,这两者等价.
那么好了,我们可以把所有路线,都变为过根的次数.
我这里用的是以1点为根,树为一条链的直接计算,其实是一样的.
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
int a[MAXN],b[MAXN];
int main(int argc ,char const *argv[])
{
#ifdef noob
freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
#endif
int n,m;
cin>>n>>m;
for (int i = 0; i < m; ++i)
{
int u,v;
cin>>u>>v;
u--;v--;
a[u]++,a[v]--;
}
int now = 0;
for (int i = 0; i < n; ++i)
{
now+=a[i];
b[i]+=now;
}
bool can = true;
for (int i = 0; i < n-1; ++i)
{
if(b[i]&1) can = false;
}
if(can) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}