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 的编号大. 最后的时候仅仅要从后往前遍历一次就能够了.得到全部的结果.明确这点后再加上树链剖分的思想就能够攻克了. 代码:…
L. Useful Roads time limit per test:4 seconds memory limit per test:512 megabytes input:standard input output:standard output Berland capital contains n junctions and m roads connecting pairs of junctions. All roads are one-way. As you probably know…
A. Funky Numbers 记\(a \le b\),枚举\(a\)即可. B. Walking in the Rain 二分时间,然后\(dp(i)\)表示是否能从1到达i. C. Dynasty Puzzles \(dp(i,j)\)表示字母i开头j结尾的最长长度. 每次更新时,只会涉及26个组合,所以总的时间复杂度为\(O(26n)\). D. Demonstration 取前\(K-1\)大的位置,然后顺序取1-n,根据是否为前\(K-1\)大取第\(K\)个数. E. Fools…
A. Lorenzo Von Matterhorn B.Minimum spanning tree for each edge C.Misha, Grisha and Underground D.Fools and Roads E.City Driving 题意:给你一颗基环树(有n条边,n个点的连通图),有Q个询问,求u,v之间的距离最小是多少 思路:对于一棵基环树而言,只要去掉其环上任意一条边(a , b),其边权为w ,剩下的边就可以构成一棵树 对于 u,v 之间的最小距离 , 有可能由去…
D. Fools and Foolproof Roads You must have heard all about the Foolland on your Geography lessons. Specifically, you must know that federal structure of this country has been the same for many centuries. The country consists of n cities, some pairs…
Fools and Foolproof Roads 并查集瞎搞搞就行, 有点小坑点. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define S…
H - A + B Strikes Back A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? Input The input co…
Problem Description There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if there is a road between A and B…
Description Building and maintaining roads among communities in the far North is an expensive business. With this in mind, the roads are build such that there is only one route from a village to a village that does not pass through some other village…
P2872 [USACO07DEC]道路建设Building Roads 题目描述 Farmer John had just acquired several new farms! He wants to connect the farms with roads so that he can travel from any farm to any other farm via a sequence of roads; roads already connect some of the farms…
A. Numbers Joke time limit per test:2 seconds memory limit per test:64 megabytes input:standard input output:standard output Input The input contains a single integer a (1 ≤ a ≤ 30). Output Output a single integer. Example Input 3 Output 27 题目链接:ht…