【】 To 09/17/2019

to

yyb Fibonacci nature

  1. \(gcd(f[i],f[i+1])=1\)

    prove

    \(gcd(f[i],f[i+1])\)
    \(=gcd(f[i+1]-f[i],f[i])\)
    \(=gcd(f[i-1],f[i])\)
    \(=....\)
    \(=gcd(f[1],f[2])=1)\)

  2. \(f[m+n]=f[m−1]f[n]+f[m]f[n+1]f[m+n]=f[m−1]f[n]+f[m]f[n+1]\)

  3. \(gcd(f[n+m],f[n])=gcd(f[n],f[m])gcd(f[n+m],f[n])=gcd(f[n],f[m])\)
    由上面式子得到
    \(gcd(f[n+m]=f[m−1]f[n]+f[m]f[n+1],f[n])gcd(f[n+m]=f[m−1]f[n]+f[m]f[n+1],f[n])\)
    \(=gcd(f[n+1]f[m],f[n])=gcd(f[n+1]f[m],f[n])\)
    \(=gcd(f[n+1],f[n])∗gcd(f[m],f[n])=gcd(f[n+1],f[n])∗gcd(f[m],f[n])\)
    \(=1∗gcd(f[m],f[n])=1∗gcd(f[m],f[n])\)
    \(=gcd(f[m],f[n])\)

  4. \ (gcd (f [n] , f [n + m]) = f [gcd (n, n + m)] gcd (f [n], f [n + m]) = f [gcd (n, n + m)] \)
    demonstrated
    \ (GCD (F [n-], F [n-+ m]) GCD (F [n-], F [n-+ m]) \)
    \ (= GCD (F [n-], F [n-+ m]% F [m]) = GCD (F [n-], F [n-+ m]% F [m]) \)
    \ (= GCD (F [n-], F [m]) = GCD (F [n-], F [m]) \)
    \ (= GCD (F [n-], F [(n-+ m)% n-]) = GCD (F [n-], F [(n-+ m)% n-]) \)
    which is removed in the form of divided
    Therefore, the last
    \ (GCD (F [n-], F [n-m +]) GCD (F [n-], F [n-m +]) \)
    \ ( = GCD (F [0], F [GCD (n-, n-+ m)]) = GCD (F [0], F [GCD (n-, n-+ m)]) \)
    \ (= F [GCD (n- , n + m)] \)

Graph theory foundation

(Some now know but less clear (?) Or determined

Simple path: simple path, each edge is only through a path.
Simple Loop: FIG point sequence, in addition to the same start and end points, the rest of the loop will not be repeated vertices.
FIG communication: If no communication to FIG any two nodes is called communication.
Strong communication: communicating means to strengthen the country, any two communicating nodes.
Weak communication: FIG directed weak communication means, all sides to replace the non-edge is communicating FIG.
Connectivity of: communicating the size of a dot is equal to the minimum spot size of FIG cut set.
Edge connectivity: the size of an edge connectivity FIG edge-cut size is equal to the minimum set.
Point cut sets: set of FIG \ (G = <V, E> \) , if present \ (V '\ subset V \ ) and \ (V' \ Not = \ Oslash \) , so \ (p (G-V ')> P (G) \) , and for any \ (V "\ Subset V' \) , are \ (P (G-V ') = P (G) \) , called \ (V' \) is \ (G \) point cut set. in particular, if the \ (V '\) is \ (G \) point cut set, and \ (V' \) is a unit set, i.e. \ (V ' = \ {V \} \) , called \ (V \) for the cut point

( \ (P (G) \) represents FIGS \ (G \) number of communication branches (the communication block))

Edge cut sets: set of FIG \ (G = <V, E> \) , \ (E '\ Subset E \) and \ (E' \ Not = \ Oslash \) , so \ (ps (G-E ' ) > P (G) \) , and for any \ (E '' \ Subset E '\) , are \ (P (G-E' ') = P (G) \) , called \ (E' \) is \ (G \) edge cut set (or simply cut set). In particular, if \ (E '\) is \ (G \) side cut-set, and \ (E' \) is a unit set, i.e., \ (E '= \ {E \} \) , called \ ( E \) bridged.

( \ (P (G) \) represents the number of communicating branches (communication block) graph G)

Subgraph: selecting a subset of nodes of FIG edge and a subset thereof.

Subgraph: subgraph nodes and select the same picture.
Subgraph: selecting a subset of nodes, and then select the set of edges FIG nodes associated configuration.
Edge induced subgraph: selecting a subset of one side, and select the set of nodes associated with these sides, the configuration in FIG.
No :( a connected subgraph) subgraph communicating to FIG.
A communication component :( no great connected subgraph of the drawing).
Notes: After a great means to add any nodes or edges are no longer satisfied.

Tree base

Binary tree root (rooted binary tree): Each node at most two sons (child node) of the binary tree rooted tree referred to. Often order to distinguish between two child nodes, child nodes are referred to as left and right child nodes.
In most cases, the term refers to the binary tree are rooted binary tree.
Complete binary tree (full / proper binary tree): the number of child nodes of each node are binary 0 or 2. In other words, each node or a leaf, or left and right subtrees are not empty.
Complete binary tree (complete binary tree): Only the bottom two nodes may be less than 2 degrees, and the bottom layer of nodes are concentrated in successive positions on the leftmost layer.
Perfect binary tree (perfect binary tree): depth of all leaf nodes are the same binary tree called a perfect binary tree.

Preorder: first root access, then access to the child node.
Preorder: first visit the left subtree, then visit the root, then visit the right subtree.
Postorder: first child node access, then access to the root.
Inorder traversal known and may request a further third.

The center of gravity of the tree

Definition: When a tree is the root of gravity, the size of all the sub-tree (not the entire tree itself) does not exceed half the size of the entire tree.
Find a point, the largest sub-tree nodes least all of its sub-tree, then this point is the tree of the center of gravity.
After deleting the center of gravity to produce more trees as balanced as possible.

nature:

  1. Tree in the distance and all points of a point, and the distance to the center of gravity is minimal; if there are two center of gravity, their distance and the same.
  2. The two trees are connected by an edge to give a new tree, then the path connecting the center of gravity of the original two new center of gravity of the tree in the tree.
  3. Add or delete a leaf in a tree, then its center of gravity to move up to a distance of one side only
  4. The center of gravity of a tree has at most two, and adjacent.

Seeking:
the focus of the search tree can be determined by a simple twice.

  1. Obtaining the number of first pass search nodes in the subtree rooted at each node \ (sz_u \)
  2. That the search to find the second pass \ (max_ {v \ in son (u)} \ {n-sz_u, sz_v \} \) minimum node
int ans,siz=inf;
void dfs(int u,int fa){
    sz[u]=1;
    int res=0;
    for(int i=head[u],v;i;i=e[i].nxt){
        if((v=e[i].v)==fa) continue;
        dfs(v,u),sz[u]+=sz[v];
        res=max(res,son[v]);
    }
    res=max(res,n-sz[u]);
    if(res<siz) ans=u,siz=res;
}

StarchDotted rule

Seniors:

Starch general routing problem for processing tree
nature starch is to partition the entire tree centroid
Then fucks

Select the center point as the current partition to separate the whole tree, each independently of each other sub-tree, then the subtree performed recursively partition, all points constituting a partition tree
why the center of gravity?
When considering the scale of the problem of partition, only when you select the center of gravity in order to make the sub-scale of the problem as small as possible, the center of gravity of each sub-tree size will not exceed n / 2, that is, each recursive problem size reduction of at least half, only recursive log Floor

inline void findrt(int x,int fa){//找重心
    siz[x]=1; bst[x]=0;
    for(rg int i=hd[x];i!=-1;i=e[i].nt){
        int v=e[i].v; if(v == fa || vis[v]) continue;
        findrt(v,x); siz[x]+=siz[v];
        bst[x]=max(bst[x],siz[v]);
    }
    bst[x]=max(bst[x],S-siz[x]);
    if(bst[x] < bst[rt] || rt == 0) rt=x;
}

Suppose you have to find the center of gravity, how to do?

Violence ah

After considering statistical all current in the current path of the center of gravity and the partition range \ ((u, v) \ ) can be regarded as \ ((u, S) +
(S, v) \) to subject to a statistical length k path, we can enumerate hard two sides, statistics into a global array, and then continue to divide and conquer, to do so for a path, it will only be counted as it passes through the highest point of divide and conquer, O (n ^ 2)

Statistics like some things should not statistics?

This will count to two paths from the same tree, but not legal,
considerations prior to each partition subtree to lose this tree is not legitimate in the case, also O (n ^ 2)

Shining template code that seniors play

#include<bits/stdc++.h>
#define Max(x,y) ((x)>(y)?(x):(y))
using namespace std;

const int N=1e4+5;
int k[10000005];
int n,m,dis[N],vis[N],rt,sz[N],bst[N],S,tt,q[N];
template <class t>void rd(t &x){
    x=0;int w=0;char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    x=w?-x:x;
}

int tot,head[N];
struct edge{int v,w,nxt;}e[N<<1];
inline void add(int u,int v,int w){
    e[++tot]=(edge){v,w,head[u]},head[u]=tot;
}

inline void findrt(int u,int fa){
    sz[u]=1,bst[u]=0;
    for(int i=head[u],v;i;i=e[i].nxt){
        if(vis[v=e[i].v]||v==fa) continue;
        findrt(v,u),sz[u]+=sz[v];
        bst[u]=Max(bst[u],sz[v]);
    }
    bst[u]=Max(bst[u],S-sz[u]);
    if(bst[u]<bst[rt]||!rt) rt=u;
}
inline void getdis(int u,int fa){
    q[++tt]=dis[u];
    for(int i=head[u],v;i;i=e[i].nxt){
        if(vis[v=e[i].v]||v==fa) continue;
        dis[v]=dis[u]+e[i].w,getdis(v,u);
    }
}

inline void deal(int u,int la,int fl){
    dis[u]=la,tt=0,getdis(u,0);
    for(int i=1;i<=tt;++i)
        for(int j=1;j<=tt;++j)
            k[q[i]+q[j]]+=fl;
}

inline void getans(int u){
    vis[u]=1,deal(u,0,1);
    for(int i=head[u],v;i;i=e[i].nxt){
        if(vis[v=e[i].v]) continue;
        deal(v,e[i].w,-1);
        rt=0,S=sz[v],findrt(v,u);
        getans(rt);
    }
}

int main(){
    freopen("in.txt","r",stdin);
    rd(n),rd(m);
    for(int i=1,u,v,w;i<n;++i) rd(u),rd(v),rd(w),add(u,v,w),add(v,u,w);
    S=n,findrt(1,0);
    getans(rt);
    for(int i=1,x;i<=m;++i){
        rd(x);
        if(k[x]>0) puts("AYE");
        else puts("NAY");
    }
    return 0;
}

kruskal

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+5,M=5e5+5,inf=0x3f3f3f3f;
int n,m;
ll ans=0;
template<class t>void rd(t &x){
    x=0;int w=0;char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    x=w?-x:x;
}
struct edge{
    int u,v,w;
    bool operator<(const edge&X)const{return w<X.w;}
}e[M];
int f[N];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
void kruskal(){
    for(int i=1;i<=n;++i) f[i]=i;
    for(int i=1,u,v;i<=m;++i)
        if(find(u=e[i].u)!=find(v=e[i].v)) f[f[u]]=f[v],ans+=e[i].w;
}

int main(){
    rd(n),rd(m);
    for(int i=1,u,v,w;i<=m;++i) rd(u),rd(v),rd(w),e[i]=(edge){u,v,w};
    sort(e+1,e+m+1);
    kruskal();
    printf("%lld",ans);
    return 0;
}

prim

#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int>pii;
priority_queue<pii,vector<pii>,greater<pii> >q;
const int N=2e5+5,M=5e5+5,inf=0x3f3f3f3f;
int n,m;
ll ans=0;
template<class t>void rd(t &x){
    x=0;int w=0;char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    x=w?-x:x;
}

int head[N],tot=0;
struct edge{int v,w,nxt;}e[M<<1];
void add(int u,int v,int w){
    e[++tot]=(edge){v,w,head[u]},head[u]=tot;
}

int dis[N],vis[N];
void prim(){
    memset(vis,0,sizeof(vis));
    memset(dis,inf,sizeof(dis));
    q.push(make_pair(dis[1]=0,1));
    while(!q.empty()){
        int u=q.top().second;q.pop();
        if(vis[u]) continue;
        ans+=dis[u],vis[u]=1;
        for(int i=head[u],v,w;i;i=e[i].nxt)
        if(!vis[v=e[i].v]&&dis[v]>(w=e[i].w))
        dis[v]=w,q.push(make_pair(dis[v],v));
    }
}

int main(){
    rd(n),rd(m);
    for(int i=1,u,v,w;i<=m;++i) rd(u),rd(v),rd(w),add(u,v,w),add(v,u,w);
    prim();
    printf("%lld",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/lxyyyy/p/11537503.html