[CF864F]Cities Excursions】的更多相关文章

题目大意: 一个$n(n\le3000)$个点的有向图,$q(q\le4\times10^5)$组询问,每次询问$s_i,t_i$之间是否存在一条字典序最小的路径(可以重复经过不为$t_i$的结点).若存在,求出该路径上经过的第$k_i$个结点. 思路: 将原图的边反向.考虑根据$t_i$对所有询问进行分组.对于$t_i$相同的询问,在反向图中DFS,求出每个结点到$t_i$的最小字典序路径中的下一个结点是多少,这可以转化为一个树形结构.若$s_i$与$t_i$不连通,则说明路径不存在:若$s_…
F. Cities Excursions There are n cities in Berland. Some pairs of them are connected with m directed roads. One can use only these roads to move from one city to another. There are no roads that connect a city to itself. For each pair of cities (x, y…
Description There are n cities in Berland. Some pairs of them are connected with m directed roads. One can use only these roads to move from one city to another. There are no roads that connect a city to itself. For each pair of cities (x, y) there i…
题意:给你一个有向图,多次询问从一个点到另一个点字典序最小的路径上第k个点. 考虑枚举每一个点作为汇点(记为i),计算出其他所有点到i的字典序最小的路径.(当然,枚举源点也是可行的) 首先,我们建一张反向图,从i开始dfs,以删去所有无法到达i的点. 然后,因为此时图上所有点都可以到达i,所以可以贪心地在从每一个点出发的边中只保留终点编号最小的边,而把其他边删除. 这样就可以保证路径是字典序最小的,并且从每个点到i的路径只有一条. 而题目中给出了这样一种情况: there are paths f…
A. Fair Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card. Befor…
Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18322 Accepted Submission(s): 4482 Problem DescriptionIn 2100, since the sea level rise, most of the cities disappear. Though some…
Description Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daug…
CF449B CF450D http://codeforces.com/contest/450/problem/D http://codeforces.com/contest/449/problem/B Codeforces Round #257 (Div. 2) D Codeforces Round #257 (Div. 1) B D. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megaby…
Connections between cities Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4425    Accepted Submission(s): 1263 Problem Description After World War X, a lot of cities have been seriously damag…
Connect the Cities Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3371 Description In 2100, since the sea level rise, most of the cities disappear. Though some survived cities are still connect…