[Codeforces 864F]Cities Excursions】的更多相关文章

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…
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…
题意:给你一个有向图,多次询问从一个点到另一个点字典序最小的路径上第k个点. 考虑枚举每一个点作为汇点(记为i),计算出其他所有点到i的字典序最小的路径.(当然,枚举源点也是可行的) 首先,我们建一张反向图,从i开始dfs,以删去所有无法到达i的点. 然后,因为此时图上所有点都可以到达i,所以可以贪心地在从每一个点出发的边中只保留终点编号最小的边,而把其他边删除. 这样就可以保证路径是字典序最小的,并且从每个点到i的路径只有一条. 而题目中给出了这样一种情况: there are paths f…
题目大意: 一个$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_…
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…
http://codeforces.com/contest/962/problem/E E. Byteland, Berland and Disputed Cities time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The cities of Byteland and Berland are located on the a…
A. Buses Between Cities time limit per test: 1 second memory  limit per test: 256 megabytes input: standard input output: standard output Buses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11…
A. Buses Between Cities 题目连接: http://www.codeforces.com/contest/665/problem/A Description Buses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city A departs every a mi…
题目描述: Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of…
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…