题目大意:给定一棵 N 个节点的有根树,1 号节点为根节点,每个节点有一个颜色.有 M 个询问,每次询问以 i 为根的子树中颜色大于等于 K 的有多少种. 题解:子树询问直接 dfs 序转化成序列问题.同时注意到不带修改,且可以离线,直接莫队即可. 代码如下 #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) x.…
[POJ3237]Tree Description You are given a tree with N nodes. The tree's nodes are numbered 1 through N and its edges are numbered 1 through N − 1. Each edge is associated with a weight. Then you are to execute a series of instructions on the tree. Th…
Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbered 1 throughN − 1. Each edge is associated with a weight. Then you are to execute a series of instructions on the tree. The instructions…
F. String Set Queries time limit per test:3 seconds memory limit per test:768 megabytes input:standard input output:standard output You should process m queries over a set D of strings. Each query is one of three kinds: Add a string s to the set D. I…
题目描述 Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an integer k,for every pair (u,v) of vertices is called valid if and only if dist(u,v) not exceed k…
Description 一棵n个点的树.每一个点的初始权值为1. 对于这棵树有q个操作,每一个操作为下面四种操作之中的一个: + u v c:将u到v的路径上的点的权值都加上自然数c: - u1 v1 u2 v2:将树中原有的边(u1,v1)删除,增加一条新边(u2,v2),保证操作完之后仍然是一棵树: * u v c:将u到v的路径上的点的权值都乘上自然数c: / u v:询问u到v的路径上的点的权值和.求出答案对于51061的余数. Input 第一行两个整数n,q 接下来n-1行每行两个正…
说起CSS3的新特性,就不得不提到 Media Queries .最近 Max Design 更新的一个泛读列表里,赫然就有关于 Media Queries 的文章.同时位列其中的也有前天我刚刚翻译的 IE9, Opacity 和 Alpha . 虽然标题相同,但本文并不是列表上 CSS3 Media Queries 的译文,因为原版有Demo有例子有图片,全文不长而且不难看懂,所以我也就不翻译了.基于自己已经了解到一定程度,所以就打算自己写. CSS2中有已经定义了 Media 的部分,包括类…
2654: tree 给你一个无向带权连通图,每条边是黑色或白色.让你求一棵最小权的恰好有need条白色边的生成树. 题目保证有解. 二分答案,然后跑最小生成树判断. 注意优先跑白色边. code: #include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int wx=500017; inline int read(){ int sum=0,f=1; ch…
题目如下: An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack operations are: push(1); push(2); push(3);…