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