E. Lomsat gelral Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/problem/E Description You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour. Let's call colour c dominating in the sub…
Codeforces 题面传送门 & 洛谷题面传送门 首先这个 if 与 end 配对的结构显然形成一个树形结构,考虑把这棵树建出来,于是这个程序的结构就变为,对树进行一遍 DFS,到达某个节点时,按照顺序遍历其所有儿子,如果儿子是叶子节点则执行赋值操作,否则进入到对应子树中执行相应操作,如果一个节点所有儿子对应的操作都被执行了就回溯,不难发现该过程与原程序等价. 考虑树形 dp.可以发现对于一棵非叶节点,在首次进入这棵子树时,程序中 \(x\) 的值已经确定了--就是 if v 中 \(v\)…
Peterson loves to learn new languages, but his favorite hobby is making new ones. Language is a set of words, and word is a sequence of lowercase Latin letters. Peterson makes new language every morning. It is difficult task to store the whole langua…
D. Wizards and Roads 题目连接: http://www.codeforces.com/contest/167/problem/D Description In some country live wizards. They love to build cities and roads. The country used to have k cities, the j-th city (1 ≤ j ≤ k) was located at a point (xj, yj). It…