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

如果某段和为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. Js-Html 前端系列--可伸缩菜单

    一个非常经典的Demo,自行开发可以扩展. <head> <title></title> <style type="text/css"&g ...

  2. C语言之数组

    数组 数组就是在内存空间中,开辟一个大的空间,然后再将这个大的空间均的分为若干份的小空间,每个小空间用来保存一个数据. 1). 数组的专业术语: 长度:指的能存放数据的个数 下标/索引:每一个数据所在 ...

  3. MySQL索引类型

    一.简介 MySQL目前主要有以下几种索引类型:1.普通索引2.唯一索引3.主键索引4.组合索引5.全文索引 二.语句 CREATE TABLE table_name[col_name data ty ...

  4. Docker 基础 : 网络配置

    大量的互联网应用服务包含多个服务组件,这往往需要多个容器之间通过网络通信进行相互配合.Docker 目前提供了映射容器端口到宿主主机和容器互联机制来为容器提供网络服务.接下来我们将讲述 Docker ...

  5. USACO 4.1 Beef McNuggets

    Beef McNuggetsHubert Chen Farmer Brown's cows are up in arms, having heard that McDonalds is conside ...

  6. elasticsearch基本概念

    NRT(近实时搜索) Elasticsearch是一个NRT平台.这意味着当你索引一个文件时,在细微的延迟(通常1s)之后,该文件才能被搜索到. Cluster(集群) cluster是在所有节点中保 ...

  7. Docker 搭建 etcd 集群及管理

    环境 host1 10.1.99.13 host2 10.1.99.14 host3 10.1.99.15 host4 10.1.99.12(用于测试添加删除节点) 初始化集群 host1 $ doc ...

  8. extjs底层源码实现继承分析

    先说明一下在js中一般的继承是怎么写的 var farther=function(name){ this.name=name }; farther.prototype={ constructor:fa ...

  9. Qt文字编码

    (internationalization and localization) 旨在使应用程序适用于不同的语言, 不同的区域文化, 不同目标市场的技术需求. internationalization ...

  10. JavaEE XML StAX创建

    StAX创建XML文档 @author ixenos 1. 如果通过DOM树来创建XML文件时,发现这个DOM树没有其他用途,那么这种方式就不是很高效,这时我们可以使用StAX API直接将XML树写 ...