Unplanned Queries(猜)

又是猜的..但是看了题解,有一些地方还是可以的.
是否存在一棵树,满足所有边都被走过偶数次.
给出所有需要走的路的头尾.
这题关键在于,树上两点想要走通,一种是不走根,直接互联(当然有的只能走根),第二种是走根(当然在很多时候这是浪费的),我们只关心奇偶性的情况下,这两者等价.
那么好了,我们可以把所有路线,都变为过根的次数.
我这里用的是以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;        

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值