On the arrangement of Zhejiang Jinhua map

Source: Internet
Author: User
Tags in degrees cmath

Directory

    • Graph theory
      • Basic Knowledge Reserve:
        • (1), Concept:
        • (2), the storage of graphs:
        • (3), the degree sequence:
      • Introduction to various algorithms:
        • (1), Havel–hakimi algorithm Introduction:
        • (2), Erd?s–gallai theorem Introduction:
        • (3), Traverse (DFS/BFS) (pass ...)
        • (4), DFS Forest Introduction:
        • (5), Euler circuit
        • (6), minimum spanning tree
        • (7), Matrix-tree theorem Introduction:
        • (8), shortest circuit (SSSP)
        • (9), Differential constraint system introduction:
        • (10), Johnson algorithm introduction:
        • (11), Radius/diameter (positive weight diagram) Introduction:
        • (12), Absolute Center && minimum diameter spanning tree
        • (13), topological sorting
        • (14), Hall ' s marriage theorem Introduction:
        • (15), K?nig ' s theorem Introduction:
        • (16), DAG Minimum path coverage Introduction:
        • (17), strong connected components && dual connectivity components
        • (18), cutting point and bridge
        • (19), graph theory example finishing (not finished ... ):
Graph theory Basic Knowledge Reserve: (1), Concept:

Figure G is a two-tuple (v,e), where V is called the vertex set, and E is called the edge set. They can also be written in V (g) and E (g). The element of E is a two-tuple number pair, denoted by (x, y), where x,y∈v.

(2), the storage of graphs:
    ①邻接表      ②链式前向星      ③邻接矩阵
(3), the degree sequence:

① if the degree of all vertices of figure g is in a sequence s, then S is the degree sequence of Figure G.
② considering the graph, D1, D2, ..., DN represents the degree of each point, D1 + d2 + ... + dn= 2e, each edge is calculated two times, there are even number of points of odd degrees.

Introduction of various algorithms: (1), Havel–hakimi algorithm Introduction:

Given a sequence consisting of a finite number of nonnegative integers, is there a simple graph that makes it the sequence of degrees. s= (d1,d2,..., DN) is a non-incrementing sequence consisting of a finite number of nonnegative integers. s can be simply graphical when and only if there is a poor sequence s ' = (d2-1,d3-1,..., d (d1+1) -1,d (d1+2),..., dn) contains only nonnegative integers and is simple to map.

(2), Erd?s–gallai theorem Introduction:

s= (d1,d2,..., DN) is a non-incrementing sequence consisting of a finite number of nonnegative integers. s can be simply graphical when and only if these numbers are of an even number and are set for any 1<=k<=n.
That is, the formula :

(3), Traverse (DFS/BFS) (pass ...) (4), DFS Forest Introduction:

(5), Euler circuit ① Introduction:

The necessary and sufficient condition for the undirected graph to have a Euler loop is that each point has an even number of degrees and is connected (note outliers). There is a necessary and sufficient condition for the direction graph to have a Euler loop for each point in degrees = out and edge connected. A unicom without a map, there are 2k odd points, then the K-path is required.

② Code implementation:
inline void dfs(int u) {    for(int i=head[u];i;i=head[u]) {        while (i && vis[abs(s[i])]) i=e[i].nxt;        head[u]=i;        if(i) {            vis[abs(s[i])]=1;            dfs(v[i]);            q[++top]=s[i];        }    }}
(6), minimum spanning tree ①prim/kruskal (complexity: O (n^2)/O (M log m)) ②kruskal algorithm correctness
拟阵(E,I)满足I的每个元素为E的子集。空集属于I如果A属于I,那么A的所有子集也属于I如果A,B属于I,并且|A|>|B|,那么存在一个A中不属于B中的元素u,满足B∪{u}也属于I。这样就被称为拟阵,对于拟阵,我们可以使用贪心算法从小到大或者从大到小选择。令E为边集,I为所有生成森林的集合,那么(E,I)为拟阵。常见的拟阵还有匹配拟阵和线性无关组。
③bor?vka Algorithm Introduction:

At first, each connected component is a point itself. Each round of each connected component selects the smallest edge connected to the other connected components and then merges. Time complexity O (E log V)

④ minimum bottleneck Spanning tree introduction:

Minimizes the maximum edge weight on the spanning tree.
Method 1: The minimum spanning tree must be the smallest bottleneck spanning tree.
Method 2: Two points of answer, whether the point is connected.
Analogy to find the method of K large value, first random one edge right w.
Then join the side that does not exceed this edge to traverse the graph.
If the diagram is connected, then the bottleneck does not exceed W, so just consider the edge of the edge not exceeding W.
Otherwise, the connecting points are shrunk and the edges of the edge greater than w are considered.
Reduce the size of the problem to half the time.
Expected time complexity O (m).

Introduction to the ⑤ spanning tree count:

1.Prufer sequence: A tree to get the prufer sequence by removing the vertices of the tree one after the other until two vertices are left. Consider the tree T, whose vertices are {1, 2, ..., n}. In step I, remove the leaf with the lowest marking and set item I of the Prufer sequence as the label of the adjacent vertex of the leaf. The sequence of a tree is clearly unique and has a length of n? 2.

2. Recovery: Set this prufer sequence long n? 2. First write the number 1 to N. Find the smallest number in 1 to n that does not appear in the sequence. The vertex and label of this number are linked to the vertices of the first item of the sequence, and the number is deleted from 1 to N, and the first item of the sequence is also deleted. Then each step repeats the above steps with the remaining number and remaining sequence in 1 to N. Finally, when the sequence is used up, the vertices of the last remaining two numbers in 1 to n are connected.

3.Cayley theorem: The number of spanning trees for complete graphs is n^ (n-2). If the degree of each point is Di, then the number of spanning trees is (n-2)!/(d1-1)!/(d2-1)!/.../(dn-1)! Each connected block size is AI, so add some edges to connect these connected blocks to the number of spanning trees A1A2... an (A1+a2+...+an) ^ (n-2) times.

(7), Matrix-tree theorem Introduction:

    令G=D-A,然后去除G的任意一行一列G’,G’的行列式即生成树个数。有向图计数,即树形图个数。这里的D变为每个点的入度,删去第i行第i列为从第i个点出发的树形图个数。
(8), the shortest circuit (SSSP) ① Introduction:

Dijkstra/Bellman Ford algorithm (Time complexity O (m log n) or O (nm))
Floyd algorithm (O (n^3))/ Johnson algorithm (negative weight)((NM log n))

① Algorithm Correctness:

Dijkstra Greedy
Bellman Ford Dynamic Planning

② some variants:

Benquan is 0/1.
Double-ended queue, if 0 is inserted at the head, otherwise inserted at the tail.
Total length not exceeding W, positive right
Use 0.. W's Bucket + list maintains these points, time complexity O (m+w).

③ Shortest Path tree (figure):

(9), Differential constraint system introduction:

According to the shortest path with inequality dis (v) <=dis (u) +w (u,v), there is exactly one such u satisfying condition. And so the computed dis (v) is the largest. , for some S (v) <=s (u) +w (u,v), it is possible to model the shortest circuit.

When the solution is unique, it is the shortest way to find the original. Take the original image and reverse it, and seek the longest way. A label corresponds to the minimum value that can be taken, and one is the maximum value. If the same, the solution is unique.

(10), Johnson algorithm introduction:
首先给图中每个点一个标号h(v), 把每条边(u,v)边权改成w(u,v)+h(u)-h(v)。对于s-t的一条路径p,权值为


所以不会改变最短路。从1号点出发跑一遍最短路,记h(v)=dis(v)。由不等式可以得到dis(u)+w(u,v)>=dis(v),也就是改完之后边权非负。之后可以每个点用Dijkstra跑。
(11), Radius/diameter (positive weight diagram) Introduction:
u的偏心距:ecc(u)=max dis(u,v)直径 d=max ecc(u)半径 r=min ecc(u) (d≠2r)中心 arg min ecc(u) (要求定义在点上)绝对中心 (可以定义在边上)

(12) Absolute Center && minimum diameter spanning tree ① Absolute Center Introduction:
固定一条边(u,v),考虑上面的点p的偏心距。假设第三个点是w, dis(p,u)=x那么对应的折线为 min(x+dis(u,w), w(u,v)-x+dis(v,w))。那么偏心距为n条折线的最大值形成的折线。按左端点排序维护一下。时间复杂度O(nm log n)

② minimum diameter Spanning tree introduction:

The absolute center of the shortest-path tree proves:

注意一棵树T有直径为半径的两倍(对绝对中心来说)。如果最小直径生成树T’不包含绝对中心,那么取T’的绝对中心v,显然矛盾。
(13), topological sorting

Each time you get rid of the points in the graph with a degree of 0. Time complexity O (n+m). If the final is not an empty set then this figure is not a dag. Otherwise, each point in the degree is not 0, that is, each point can choose a forward trend, along the way before the principle of the drawer must be able to find the same point, that is, a ring.

The topological sequence of ① dictionary sequence with minimal order

Each point has a different label, so the topological order is minimized. Change the queue of the topology sort to the priority queue.

A variant of ② minimum topological order

So that the final topological order in 1 of the position as far as possible, if the same position compared to 2, and so on. First of all, consider how to find the first 1 position, you can reverse the original, and then every time except 1 elements, until the queue only 1 left. This is the last occurrence of the 1 in the inverse diagram, which is the earliest of the original. Depending on whether the diagram is in a queue, the graph is divided into two parts, which are processed in the corresponding diagram in the same way 2, and so on. It is easy to find the elements that are as large as possible to get out of the team and complete the above process. So the inverse graph is equivalent to the maximum dictionary order.

(14), Hall ' s marriage theorem Introduction:

For a binary graph g= (x,y,e), remember S is a subset of X, and N (s) is a bit of a neighbor's set in all S.
A graph has a complete match when and only if all subsets of x have | s|<=| N (S) |
Generalization of general graphs:

Inference: Each regular binary graph has a complete match.

(15), K?nig ' s theorem Introduction:

Minimum point coverage = Maximum match (equivalent to maximum flow minimum cut theorem)
Maximum independent set = number of points-Maximum match (independent set is the complement of point overrides)
Minimum edge overlay = Maximum Independent set (each point in a separate set requires an edge to overwrite)

(16), DAG Minimum path coverage Introduction:

Cover all edges: the lower bound of each edge is set to 1, and then the minimum flow is calculated.
Cover all points: Create a binary graph, for u->v edges, as in the binary graph (u,v '), then the answer is point-maximum match.
Dilworth theorem: maximum reverse chain = minimum chain coverage

(17), strong connected components && dual connectivity components ① strong connected components:

Tarjan:
First, each point is labeled according to the order in which DFS is accessed, and the timestamp of this point is recorded.
Each point then maintains a low value, which means that the point at which the timestamp is minimized is accessed by the tree edge and back edge.
If a point can be accessed to the earliest point as this point, a new strong connected component is formed.
A graph that shrinks the strongly connected component will form a DAG.

② Code (TARJAN):
void tarjan(int pos){    vis[stack[++index]=pos]=1;//入栈并标记    LOW[pos]=DFN[pos]=++dfs_num;    for(int i=pre[pos];i;i=E[i].next){        if(!DFN[E[i].to]){            tarjan(E[i].to);            LOW[pos]=min(LOW[pos],LOW[E[i].to]);        }        else if(vis[E[i].to]) LOW[pos]=min(LOW[pos],DFN[E[i].to]);    }    if(LOW[pos]==DFN[pos]){        vis[pos]=0;        size[dye[pos]=++CN]++;//染色及记录强连通分量大小        while(pos!=stack[index]){            vis[stack[index]]=0;            size[CN]++;//记录大小            dye[stack[index--]]=CN;//弹栈并染色        }        index--;    }}
③ Dual Unicom Component Introduction:

Point connectivity: The smallest point set makes the graph disconnected after deletion
Edge connectivity: The smallest edge set makes the graph disconnected after deletion
If the point connectivity of a graph is greater than 1, then the point is double connected, and the edge is connected similarly.
The double Unicom component is the maximal double-link sub-graph in the graph.

(18), cut Point and bridge ① introduction:

Consider the Dfs tree, where each non-tree edge corresponds to a point-to-ancestor path. For a non-tree edge, just mark the corresponding edge. For example (U,V) This non-tree edge, as long as the U point +1 mark, the V-point hit 1 mark. V to v the number of times the tree edge of the father is covered by all markers within the subtree. Cut the point similarly (pay attention to the root node and leaf node).

Note marking this process can be done online. You can use a and check set to maintain the points in the current dual-link component, recording the highest point in each of the dual-connectivity components. Then for a non-tree edge, the violence merges these points together. Because an edge is merged at most once, it needs not to exceed the O (m) and check set operation. A tree is formed when the side of the double-link component is shrunk.

② Example (2-SAT):

The two-dollar limit for a bunch of variables, asking if there is a valid assignment.

First, each variable is split by two points, and Xi and Xi ' represent xi=1 or 0 for a restriction such as Xi or XJ, from Xi ' to the XJ edge, from XJ ' to the XI edge, indicating that if XI takes 0, then XJ takes 1 and vice versa. At the same time, for xi=1 such restrictions can be converted to Xi or XI, so from XI ' to Xi's edge, indicating that Xi ' cannot be taken. For such graphs, the strong connected component is obtained. The necessary and sufficient conditions for the solution are not in the same strongly connected component for each variable XI and Xi '. Solution, for a variable XI and Xi ', as long as the strong connected components in the Tarjan algorithm can be formed early. Perceptual knowledge: If Xi can reach Xi ', then the strong connected component of Xi ' will be formed early.

(19), graph theory example finishing (not finished ... ): Allowed Letters (CF 1009 G) code implementation:
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include < algorithm>using namespace Std;const int n=1e5+10;const int m=63;int m,x,len,l,t;int a[n],ans[n],js[7],f[m+2][n];    char s[n],ch[9];inline int read () {int N=0,f=1;char ch=getchar ();    while (ch< ' 0 ' | | ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch<= ' 9 ' && ch>= ' 0 ') {n= (n<<3) + (n<<1) +ch-' 0 '; Ch=getchar ();} return n*f;}        inline int work (int x) {for (int k=0;k<=m;++k) {int jc=0;        for (int i=0;i<6;++i) if ((k>>i) &1) jc+=js[i];    if (F[K][LEN]-F[K][X]&LT;JC) return 0; } return 1;}    int main () {scanf ("%s%d", s+1,&m);    Len=strlen (s+1);        Preprocess for (int i=1;i<=len;++i) {a[i]=m,ans[i]=-1;    ++js[s[i]-' a '];        } for (int i=1;i<=m;++i) {scanf ("%d%s", &x,ch);        L=strlen (CH), t=0;        for (int j=0;j<l;++j) t|=1<< (ch[j]-' a ');   a[x]&=t; } for (int k=0;k<=m;++k) for (int i=1;i<=len;++i) f[k][i]=f[k][i-1]+ (BOOL) (a[i]&k);            for (int. i=1;i<=len;++i) {for (int j=0;j<6;++j) {--js[j];                 if (((a[i]>>j) &1) && work (i)) {ans[i]=j;            Break        } ++js[j];            } if (ans[i]==-1) {printf ("impossible\n");        return 0;    }} for (int i=1;i<=len;++i) Cout<<char (ans[i]+ ' a '); return 0;}
Revmatching (TCO 1 a hard) Valid BFS? (CF 1037 D)
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <vector > #include <queue> #include <algorithm>using namespace std;const int n=2e5+10;int n,x,y,res;int Vis[n], Head[n];vector<int> g[n],ans;queue<int> q;struct Node {int a,b,nxt;}    E[n];inline int read () {int N=0,f=1;char ch=getchar ();    while (ch< ' 0 ' | | ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch<= ' 9 ' && ch>= ' 0 ') {n= (n<<3) + (n<<1) +ch-' 0 '; Ch=getchar ();} return n*f;} inline int cmp (int x,int y) {return e[x].b<e[y].b;}    inline void init () {for (int i=1;i<=n;++i) e[e[i].a].b=i;        for (int i=1;i<=n;++i) {sort (G[i].begin (), G[i].end (), CMP);    for (int j=0;j<g[i].size (); ++j) res=g[i][j];    }}inline void BFs (int s) {Q.push (s);    Vis[s]=1;        while (!q.empty ()) {int U=q.front ();        Q.pop ();        Ans.push_back (U); for (int i=0;i<g[u].size (); ++i) {int v=g[u][i];            if (Vis[v]) continue;            Vis[v]=1;        Q.push (v);    }}}inline int PD () {for (int i=0;i<ans.size (); ++i) if (E[i+1].a!=ans[i]) return 0; return 1;}    int main () {n=read ();        for (int i=1;i<=n-1;++i) {x=read (), Y=read ();        G[x].push_back (y);    G[y].push_back (x);    } for (int i=1;i<=n;++i) e[i].a=read ();        if (e[1].a!=1) {printf ("No");    return 0;    } init ();    BFS (1);    if (PD ()) printf ("Yes");    else printf ("No"); return 0;}
Cycle (HDU 5215) Aviation Control (NOI 2010)

Topic Description:

There are n flights that take off in turn, only one plane takes off at a time, and there is a limit of M: the first limitation, I aircraft must take off before the time of C (i). The second limitation is that the first aircraft must take off before the first J aircraft.

Ask:
A viable takeoff plan. The earliest departure time for each aircraft. N<=2e3, M<=1e4

Solution

    倒过来变成每个飞机在某个时刻之后可以起飞。    第二问变成每个飞机最晚什么时候起飞。    直接用拓扑排序的做法即可。
Abland Yard (AGC C)

Topic Description:

Give you a map of the direction, each point is labeled 01. Ask if there is a path for all 01 strings, so that the number of points passing through the path is linked together to get 01 strings.

Solution

    这里只讨论二分图。    最大匹配: Hungarian/Hopcroft-Karp/Dinic    最大权匹配: KM/费用流    判断是否存在奇环,只要看是不是二分图即可。    判断是否存在偶环,首先看每条非树边对应的环是不是偶环。    如果存在那么就找到了偶环。    否则考虑如果两个奇环相交,那么去除中间部分就会形成一个偶环。    所以对于奇环的非树边只要暴力访问树边打上标记,如果已经有标记了就说明存在奇环。    时间复杂度O(n+m)
Cycling City (CF 295 E)

Topic Description:

You have an n-point M-bar without a graph. (N, M<=2e5)
Ask if there are two points, so there are three simple paths between the two points, and the three simple roads have no common points.

Solution

    如果两条非树边对应的环有交,那么一定可以找到这样的两个点。否则不存在。
Hangar Hurdles (CERC 16)

Topic Description:

* * There is a n*n grid chart, some lattice is feasible, some lattice is a barrier. (n<=1000 q<=300000)
Q A query, want to push a square box from (R1,C1) to (R2,C2), ask the maximum size of the box. (The starting point is the midpoint of the square box) * *

Solution

    首先从障碍开始bfs,求出每个格子最近的障碍。然后变成了求一条路径,使得路径上的最小值最大。求最大生成树,然后在上面倍增询问即可。
Life of the party (Ontak) allowed Letters (CF 1009 G)

Topic Description:

You have 6 kinds of letters, and the first letter has CI. You want to use these letters in a string, where there are some conditions where I can only fill a subset of a letter. Ask what is the smallest string you can fill out in the dictionary order. (Sum ci<=10^5)

Solution

    首先求出最大匹配,下面考虑左边点的情况。我们将匹配中的边从右往左连,不在匹配中的边从左往右连。这个时候一条增广路成为一条连续的路径。从每个左边未匹配的点还是遍历,如果被一个左边的点被访问到,说明存在一条增广路,也就是不一定在最大匹配中。所有没有被访问到的点一定在最大匹配中。
Revmatching (TCO 1 A hard)

Topic Description:
Given a two-point graph of n points, each edge has a side right. Find a edge and a minimum set of edges so that there is no complete match after deleting the edge set. N<=20
Solution

    根据Hall定理,只要存在一个集合S,使得|N(S)|<|S|,则不存在完备匹配。于是我们枚举S集合,然后贪心删除边集使得|N(S)|<|S|。
Bajtman i okr?g?y Robin (Ontak 2015)

Topic Description:

There are n bandits, each robber will at the moment L to time R robbery, will cause C loss. In a moment, you can choose to catch a robber, the robber will not cause loss after being caught. You must catch as many robbers as possible to make the loss as small as possible. (n<=5000)

Solution

    按强盗从大到小排序,贪心选取每个强盗能不能抓。判断一些强盗能不能抓完,可以按左端点排序,使用优先队列维护右端点。贪心算法的正确性: 考虑匈牙利算法,从大到小一个一个匹配,一个点一旦在匹配中,那么一直在匹配里面。
Examples of non-well-known

Topic Description:

There are n dots (x_i,y_i) on the plane, which dye the dots red-blue so that the difference between the number of red and blue dots per row is less than 1. Generates 01 strings of 2^n (which are connected to each other) so that all 01 strings of length n are present.

Not well-known example 2

Topic Description:
There are n points, each point has a weighted AI, and the Benquan between the two points is (Ai+aj) mod M. Ask the minimum spanning tree. (N<=1E5,0<=M,A_I<=1E9)

On the arrangement of Zhejiang Jinhua map

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.