Codeforces Round #121 (Div. 1) C. Fools and Roads time limit per test :2 seconds memory limit per test : 256 megabytes They say that Berland has exactly two problems, fools and roads. Besides, Berland has n cities, populated by the fools and connecte…
They say that Berland has exactly two problems, fools and roads. Besides, Berland has n cities, populated by the fools and connected by the roads. All Berland roads are bidirectional. As there are many fools in Berland, between each pair of cities th…
题目链接:Codeforces 191C Fools and Roads 题目大意:给定一个N节点的数.然后有M次操作,每次从u移动到v.问说每条边被移动过的次数. 解题思路:树链剖分维护边,用一个数组标记就可以,不须要用线段树. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1e5 + 5; int N, Q, ne, fi…
主题链接~~> 做题情绪:做了HDU 5044后就感觉非常easy了. 解题思路: 先树链剖分一下,把树剖分成链,由于最后全是询问,so~能够线性操作.经过树链剖分后,就会形成很多链,可是每条边都有编号,相当于一个数组进行线性操作,这样.如果在 u ~ v 去都添加 1 .那么能够让 sum [ u ] += 1 ; sum [ v + 1 ] -= 1 ; 这里如果 v 的编号大. 最后的时候仅仅要从后往前遍历一次就能够了.得到全部的结果.明确这点后再加上树链剖分的思想就能够攻克了. 代码:…