先思考一下序列上应该怎么做。

如果某段和为x,并且x为偶数,那么比x小的偶数,一定是这段的子段。

如果某段和为x,并且x为奇数,那么比x小的奇数,一定是这段的子段。

因此....只要寻找最大的连续的和为奇数的是多少,偶数的是多少。然后对询问就可以o(1)输出了。

推广到树上,就是只要计算路径上最大的奇数和最大的偶数。 树dp即可解决。 树dp写搓了。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
#include<ctime>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
} int n,q;
bool f[],L[];
struct Edge
{
int u,v,w,nx;
}e[];
int sz,h[]; int mx[][];
int max0,max1;
int a[]; struct X
{
int from, num;
X()
{
num = ;
from = ;
}
X(int From,int Num)
{
from=From;
num=Num;
}
bool operator < (const X &a) const {
return num<a.num;
}
}; void add(int a,int b,int c)
{
e[sz].u=a; e[sz].v=b; e[sz].w=c; e[sz].nx=h[a]; h[a]=sz++;
} struct cmp{
bool operator ()(int &a,int &b)
{
return a<b;
}
}; void dfs(int x)
{
f[x]=; priority_queue<X>Q[]; for(int i=h[x];i!=-;i=e[i].nx)
{
if(f[e[i].v]==) continue; mx[x][e[i].w%]=e[i].w; dfs(e[i].v); if(mx[e[i].v][]!=-) Q[(e[i].w+mx[e[i].v][])%].push(X(e[i].v,e[i].w+mx[e[i].v][]));
if(mx[e[i].v][]!=-) Q[(e[i].w+mx[e[i].v][])%].push(X(e[i].v,e[i].w+mx[e[i].v][])); if(mx[e[i].v][]==-||mx[e[i].v][]==-)
{
if(Q[(e[i].w)%].empty()) Q[(e[i].w)%].push(X(e[i].v,e[i].w));
}
} if(!Q[].empty()) mx[x][]=Q[].top().num;
if(!Q[].empty()) mx[x][]=Q[].top().num; int p=; X f1,f2,g1,g2;
if(!Q[].empty()) { f1=Q[].top(); Q[].pop(); }
if(!Q[].empty()) { f2=Q[].top(); Q[].pop(); } if(!Q[].empty()) { g1=Q[].top(); Q[].pop(); }
if(!Q[].empty()) { g2=Q[].top(); Q[].pop(); } if(f1.num+f2.num!=) a[p++]=f1.num+f2.num;
if(g1.num+g2.num!=) a[p++]=g1.num+g2.num; if(f1.from!=g1.from)
{
if(f1.num+g1.num!=) a[p++]=f1.num+g1.num;
} else
{
if(f1.num+g2.num!=) a[p++]=f1.num+g2.num;
if(f2.num+g1.num!=) a[p++]=f2.num+g1.num;
} for(int i=;i<p;i++)
{
if(a[i]%==) max0=max(max0,a[i]);
if(a[i]%==) max1=max(max1,a[i]);
} } int main()
{
while(~scanf("%d%d",&n,&q))
{
memset(f,sz=,sizeof f);
memset(h,-,sizeof h);
memset(L,,sizeof L); for(int i=;i<n;i++)
{
int u,v,w; scanf("%d%d%d",&u,&v,&w);
add(u,v,w); add(v,u,w);
} memset(mx,-,sizeof mx);
max0=max1=-; dfs();
for(int i=;i<=q;i++)
{
int x; scanf("%d",&x);
if(x<) printf("No\n");
else
{
if(x%==)
{
if(max0>=x) printf("Yes\n");
else printf("No\n");
}
if(x%==)
{
if(max1>=x) printf("Yes\n");
else printf("No\n");
}
}
} }
return ;
}

ACdream 1028 Path的更多相关文章

  1. [ACdream]瑶瑶带你玩激光坦克

    题目链接:http://acdream.info/contest?cid=1269#problem-B Problem Description 有一款名为激光坦克的游戏,游戏规则是用一个坦克发出激光来 ...

  2. POJ 3126:Prime Path

    Prime Path Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit St ...

  3. NodeJs之Path

    Path模块 NodeJs提供的Path模块,使得我们可以对文件路径进行简单的操作. API var path = require('path'); var path_str = '\\Users\\ ...

  4. 【原】实时渲染中常用的几种Rendering Path

    [原]实时渲染中常用的几种Rendering Path 本文转载请注明出处 —— polobymulberry-博客园 本文为我的图形学大作业的论文部分,介绍了一些Rendering Path,比较简 ...

  5. Node.js:path、url、querystring模块

    Path模块 该模块提供了对文件或目录路径处理的方法,使用require('path')引用. 1.获取文件路径最后部分basename 使用basename(path[,ext])方法来获取路径的最 ...

  6. VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

    1.问题描述 由于安装VS15 Preview 5,搞的系统由重新安装一次:在用vscdoe编译go语言时,出现以下问题: # odbcexec: "gcc": executabl ...

  7. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  8. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  9. Thinking in Unity3D:渲染管线中的Rendering Path

      关于<Thinking in Unity3D> 笔者在研究和使用Unity3D的过程中,获得了一些Unity3D方面的信息,同时也感叹Unity3D设计之精妙.不得不说,笔者最近几年的 ...

随机推荐

  1. Java构造器的深入理解

    [构造器与方法的深入理解] 构造器的深入理解 [博主]高瑞林 [博客地址]http://www.cnblogs.com/grl214 [博客地址]http://www.cnblogs.com/grl2 ...

  2. [bzoj2957][楼房重建] (线段树)

    Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...

  3. Mybatis学习笔记(四) 之动态SQL语句

    动态SQL mybatis 的动态sql语句是基于OGNL表达式的.可以方便的在 sql 语句中实现某些逻辑. 总体说来mybatis 动态SQL 语句主要有以下几类: 1. if 语句 (简单的条件 ...

  4. vim 模式基础操作

    作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 前言 虽然Emacs已经可以完成大部分的编辑操作,但有时候为了方便也会用到vim.所以记录了 ...

  5. 首页导航点击A连接跳转并添加上背景色,

    <style> ul li { float: left; height: 50px; width: 120px; color: white; text-align: center; mar ...

  6. 启动web项目,报内存不足错误的解决方法

    Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: Java heap space 原因: 在 ...

  7. 【NOIP2014】Day1题解+代码

    Day1 T1 签到题,模拟一下随便写就能过. 不过小心像我一样表打错傻逼的调了10min. #include <algorithm> #include <iostream> ...

  8. Girl Develop It Chapter Leaders at 2015 Annual Leadership Summit

    Girl Develop It Chapter Leaders at 2015 Annual Leadership Summit Corinne Warnshuis, Executive Direct ...

  9. linux下正确安装jsoncpp

    要安装jsoncpp,首先要下载好scons,再去安装jsoncpp scons下载地址:wget http://prdownloads.sourceforge.NET/scons/scons-2.2 ...

  10. 从A页面跳转到B页面,从B页面按浏览器自带按钮返回到A页面并且刷新页面--手机操作浏览器自带返回并自带刷新

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...