Play ♂ Games

Source: Internet
Author: User

Play ♂ Games

Give a figure with a point of 2 in addition to 1 and N. Each time two people take a side right. When from 1 to n when the last person to lose. Ask whether the winner will win.

First, the case of multiple chains is bound to be converted into a chain. Because no one will go to get 1, when the edge and for even, the chain has an odd number of edges win, otherwise win.

Therefore, when the edge right and the even number, the initiator wants odd chains. I want even chain more. Conversely, it is reversed. The minimum value of the odd chain is counted and the minimum value of even chain is compared.

#include <cstdio>#include <algorithm>using namespace std;typedef long long LL;const LL maxn=2e5+5;LL n, m;struct Edge{    LL to, nxt, v;}e[maxn*2];LL fir[maxn], cnte;void addedge(LL x, LL y, LL z){    Edge &ed=e[++cnte]; ed.v=z;    ed.to=y; ed.nxt=fir[x]; fir[x]=cnte; }LL sum[2], esum;void dfs(LL u, LL p, LL cnt, LL minm){    LL v;    if (u==n){ sum[cnt&1]+=minm; return; }    for (LL i=fir[u]; i; i=e[i].nxt){        if ((v=e[i].to)==p) continue;        dfs(v, u, cnt+1, min(minm, e[i].v));    }}int main(){    scanf("%lld%lld", &n, &m); LL x, y, z;    for (LL i=1; i<=m; ++i){        scanf("%lld%lld%lld", &x, &y, &z); esum+=z;        addedge(x, y, z); addedge(y, x, z); }    dfs(1, 0, 0, 0x7fffffff);    if (!(esum&1)&&sum[1]>=sum[0]) puts("Yes");    else if ((esum&1)&&sum[0]>=sum[1]) puts("Yes");    else puts("No");    return 0;}

Play ♂ Games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.