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

如果某段和为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. 分享php工作中遇到的一些探究和技巧【2】

    1 如何定义linux和window通用的文件分隔符号 DIRECTORY_SEPARATOR :  目录分隔符,是定义php的内置常量.在调试机器上,在windows我们习惯性的使用"\& ...

  2. Kattis - Fenwick Tree(树状数组区间更新单点求值)

    Fenwick Tree Input The first line of input contains two integers NN, QQ, where 1≤N≤50000001≤N≤500000 ...

  3. oracle数据库一些用户管理语句

    查询所有数据库用户 select * from dba_users 查看数据库名称 select name from v$database 查看权限 select * from user_sys_pr ...

  4. shell 脚本中for循环

    昨天很痛苦的搞了一天的for循环,在服务器上运行没啥问题,在设备上运行总是不行,部分代码如下: for(i=1;i<$cnt+1;i++)do echo "xxxx"  &g ...

  5. linux内核之链表操作解析

    本文只是对linux内核中的链表进行分析.内核版本是linux-2.6.32.63.文件在:linux内核/linux-2.6.32.63/include/linux/list.h.本文对list.h ...

  6. nginx(1)

    下一篇:nginx(2) 一.engin X 市场的服务器非常的多,这里简单介绍几种常用的. Apache:源代码开放,跨平台,可移植,且支持的模块非常丰富,虽然在速度性能上不如其他轻量级的web服务 ...

  7. Pelican搭建静态博客

    前言 一直以来都希望拥有属于自己的个人博客,随性发点信息,写点技术感想,记录自己的生活,重要的是不受广告的影响.不被河蟹.不会担心有一天被莫名其妙地消失. 之前看过一篇文章:"像黑客一样写博 ...

  8. spark MLLib的基础统计部分学习

    参考学习链接:http://www.itnose.net/detail/6269425.html 机器学习相关算法,建议初学者去看看斯坦福的机器学习课程视频:http://open.163.com/s ...

  9. 在IT界取得成功应该知道的10件事

    导读:人人似乎都同意IT行业是一个艰难领域,但怎样才能克服逆境,成为一名成功的IT专业人士呢?下文这些特质应该是关键.此文作者Jack Wallen,他在前段时间写过不少文章讨论IT职场,比如退出IT ...

  10. Jdk 1.8*安装并配置

     转载自:http://www.cnblogs.com/zlslch/p/5658399.html 简单说下,jdk1.8*的下载,见http://www.cnblogs.com/zlslch/p/5 ...