DP & graph theory DAY 5 am

  DP & graph theory DAY 5 am

 

 POJ 1125 Stockbroker Grapevine

 There are N number stockbroker can pass messages to each other, between them there are some one-way
communication path. Now there is a message to be delivered by a person start to all other
men, and should be delivered by which individuals can in the shortest time for all to take
receipt of the message.

Solution

Global Shortest

Floyd

 

 

POJ 1502 MPI Maelstrom

Given N number of information transmission between a lower triangular matrix, the time required for the processor, request information
transmitted to all other processors from the first processor time required maximum.

Solution

Single Source longest path dij (nm logn)

 n ^ 2 logn

 

 

 

POJ 1511 Invitation Cards

N points of M have edges to FIG asking for all i , from the point a starting point i and
the return point 1 the time required minimum.

Solution

# Forward build Figure + single-source shortest
# reverse the construction diagram + single-source shortest, it is to have the edge in turn, starting from point 1 dij actually reverse shortest path

 

 

 

POJ 1724 ROADS

There are N cities and M unidirectional road, each road having a length and two charge properties.
In seeking the total cost does not exceed K premise from city 1 to the city N Shortest Path.

Solution

Dijkstra , while maintaining the current path of the total cost, cost more than the upper limit of the state no longer transfer 

For each point split into k points, (u, 0), (u, 1), ....... (u, k)

Layered graph

 

 

 

 

 

 POJ 1797 Heavy Transportation

 Gives N points M no to FIG edges, each edge has a maximum load.
Request from point 1 to point N maximum weight can pass.

 Solution

1. bipartite answer, assume that the maximum load> = mid, only by limiting the weight> = mid side, added to the figure, the connectivity is determined

2. KRUS maximum spanning tree, 1 --- n connectivity is determined, the communication is terminated

   Descending plus side, the first 1 and n connectivity so that edge is the answer

   Disjoint-set maintenance before adding k connectivity when large side

3.dijkstra    variant single-source shortest path length to the right side of the minimum path

   if ( dis[v] < min(dis[u],w) )  dis[v] = min( dis[u] , w )

 

 

 

POJ 1062 costly dowry ( http://poj.org/problem?id=1062)

PS: Note that chieftaincy is not necessarily the highest

 

Solution

 For the first position in ascending order, and then enumerate [Emirates, Emirates + m] of this interval as the maximum position
 Running time interval length of the shortest path

 

Dij ran away from super original point, and then to point 1 

 

1. FIG construction, the article as a point, as substitutes side length pricing

   Such as chiefs daughter <------ crystal ball weights are discounted prices

   From an article exchange is to promise a path Emirates

   Irrespective of the status of limit, starting from the chiefs promised to seek a single source shortest path to know a little from any desired gold

   This is a reverse shortest reverse dij

2.  Enumeration grade range position, the point is not within the range not through the level position, enum  O ( N
    for "indirect transaction" method, a difference of about enumeration endpoint hierarchy interval <= m

    I.e. max - min <= m, in order to make more room in a transaction section, we set the max-min = m

    Then consider this transaction can be inside the range, it is illegal in the figure deleted

    

    See the data, m may be large, but small n, then consider enumerated as the section end point

    

Figure 3. The remaining legitimate reverse run dij 

 

 

 

 

BZOJ 3040 Shortest *

N 个点, M 条边的有向图,求点 1 到点 N 的最短路(保证存在)。
1 N 1000000, 1 M 10000000
By lydrainbowcat
边集分为两部分:
# 随机生成
# 输入给出

Solution

1. 采用高效的堆来优化 Dijkstra 算法。
    # 斐波那契堆
    # 配对堆

       dij ,一个大图就凉

       SPFA太小,凉

       dij 用支持修改删除的堆,配对堆

2.用 pq 做,随机生成的数据不要,直接删掉

   https://paste.ubuntu.com/p/Mp2fXMKv8J/

   

  *d就是只输入不赋值

 

priority_queue  STL实现合并

启发式合并,两个堆,A,B,把较小的堆拆了,放到较大的堆里面

每个点最多产生 logn 次代价

 

 

 

最小生成树算法

Prim

 

// Prim

void prim() {
    memset(dis, inf, sizeof dis);
    heap.push(data(1, dis[1] = 0));
    int ans = 0;
    while (!heap.empty()) {
        data t = heap.top(); heap.pop();
        if (dis[t.u] != t.d)continue;
        ans += t.d;
        for (int i = hd[t.u], v, w; i; i = nt[i])
            if (v = to[i], w = vl[i], dis[v] > w)
                heap.push(data(v, dis[v] = w));
    }
}

 

 

 

 Kruskal

复杂度卡在排序上

证明依赖于拟阵的知识。 

 

> 拟阵

独立集 

交换性的推论:一个集合的所有极大独立集大小都相同。

                         如果不相同,就交换

 

 

线性相关:向量*常数,加起来,是0向量

拟阵最优化

 

 

 

POJ 1258 Agri-Net

N 个村庄,村庄之间形成完全图。现给出邻接矩阵,选择总
长度尽可能小的边将 N 个村庄连通。

 >最小生成树

POJ 2421 Constructing Roads

N 个村庄,有一些道路已经存在,现在希望用最少的总长度
将所有村庄连通。

>将已经存在道路设置长度为 0

 

POJ 2560 Freckles

给出平面上 N 个点,求将所有点连通的最小距离和。

>O(N2) 建边。

 

 

POJ 1789 Truck History

N 个编号,每个编号均为 7 位数。两个编号之间的距离定义
为其不同位个数,由一个编号生成另一个编号代价为两个编号的
距离。希望用最小总代价从某一编号开始生成所有编号。

>O(N2) 建边。

  一开始没看明白T,距离就是比较两个编号各位数字,然后计算有几位不同

 

 

BZOJ 1601 灌水

>Solution

 

 

BZOJ 2743 滑雪与时间胶囊

Solution

高度从大到小,边从小到大

能够到达的景点容易通过 DFS BFS 求出。

最优解应当构成树形,所需要的时间即为所有边长度之和。易联想到用最小生成树 Kruskal 算法解决本问题。

如何设置 Kruskal 时边的优先级?如何保证选出的有向边集使得每个点从 出发可达?

以到达点高度为第一关键字,边长度为第二关键字。到达点高度高的边优先,同样高时边长度短的优先。 

 

BZOJ 2561 最小生成树 *

(放到晚上)

 

 

 

树上倍增

 

 序列倍增

 

 

树上倍增

 

f[i][j]表示结点编号

如何求解 u 向上移动 k 步是哪个点?

 

最近公共祖先

 

 

 

 Tarjan 支持离线

DFS序+RMQ 支持在线

 树上DFS有回溯操作,每个点被放进的次数就是相邻边数,所以序列长度2n

 记录每个点第一次被放进序列,最后一次放进序列

 对于两个点,A,B,最晚的A,最早的B,卡一个区间,区间内出现过 LCA(A,B),而且不存在比他深的节点,区间深度最小,就是 LCA 

 

 

 

向上路径

如何求解从 u v 路径上边权最值?保证 v u 的祖先。

 

 

 树上路径

 

如何求解从 u v 路径上的边权和?

将路径拆分为两段向上路径,分别求解其答案再合并。

 

Guess you like

Origin www.cnblogs.com/xiaoyezi-wink/p/11330413.html