D. New Year Santa Network time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output New Year is coming in Tree World! In this world, as the name implies, there are n cities connected by n - 1 roads,…
题目大意 给你一颗有\(n\)个点的树\(T\),边上有边权. 规定,\(d(i,j)\)表示点i到点j路径上的边权之和. 给你\(q\)次询问,每次询问格式为\(i, j\),表示将按输入顺序排序的第\(i\)条边边权修改为\(j\),并要求回答任取三个不同点\(c_1,c_2,c_3\),所带来的费用\(d(c_1,c_2)+d(c_1,c_3) + d(c_2,c_3)\)的期望 原题面 D. New Year Santa Network time limit per test 2 sec…
New Year is coming in Tree World! In this world, as the name implies, there are n cities connected by n - 1 roads, and for any two distinct cities there always exists a path between them. The cities are numbered by integers from 1 to n, and the roads…
题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵线段树,类似计数排序思想. #include <bits/stdc++.h> using namespace std; ; struct SegTree { ], sum[], l, r; }T[N << ]; ][N]; void pushup(int p, int c) { T[p…
D. New Year Santa Network   New Year is coming in Tree World! In this world, as the name implies, there are n cities connected by n - 1 roads, and for any two distinct cities there always exists a path between them. The cities are numbered by integer…
D. New Year Santa Network time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output New Year is coming in Tree World! In this world, as the name implies, there are n cities connected by n - 1 roads,…
[Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得这q条路径都能被满足.(如果有一条边是从a->b),而经过它的路径是从b->a,那么久不满足).只需要判断,不用输出方案. 分析 对于一个有向环,显然它可以允许各个方向的路径通过.所以我们只要把无向图里的边-双联通分量建成环,然后就不用考虑了.影响答案的只有桥. 所以我们求出所有桥,然后缩点,把图…
题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include…
Codeforces 633C Spy Syndrome 2 | Trie树裸题 一个由许多空格隔开的单词组成的字符串,进行了以下操作:把所有字符变成小写,把每个单词颠倒过来,然后去掉单词间的空格.已知操作后的字符串以及可能出现的所有单词,请输出原字符串(多组解只输出一个). 我犯的错误:数组的trie树--如果根节点是1--则其余节点要从2开始啊啊啊 #include <cstdio> #include <cstring> #include <algorithm> u…
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问,最少删除多少个字符,使得串中符合ugly串? 思路:定义dp(i, j),其中i=5,j=5,因为只需要删除2016当中其中一个即可,所以一共所需要删除的字符和需要的字符为20176,因此i和j只要5就够了. 然后转移就是dp(i,i) = 0, 如果说区间大小为1的话,那么如果是2017中的一个…