10.29-10.30Test

10.29-10.30Test

topic description practice
\(BSOJ5161\) Add small to large \ (n-\) number, each time he can not be covered by cover own number or less, find the number of each of the number of cover No brain simulation
\(BSOJ5162\) Given a directed graph, each point of a set may cover any two unreachable, seeking a minimum rounds End cover After condensing point \ (the DAG \) a \ (the DP \)
\(BSOJ5163\) Dynamic plus side, repeatedly asked \ (A \ rightarrow B \) is the shortest path largest side \ (LCA \) + violence \ (or ~ LCT \) Maintenance \ (Mst \)
\(BSOJ5169\) Seeking \ ([L, R] \ ) in the prime and the product of two prime number Magic sieve linear change
\(BSOJ5170\) Each point can be a key, each side has a key restriction, seeking \ (1 \ rightarrow n \) Shortest + Shortest layered shaped pressure ( \ (the BFS \) )
\(BSOJ5171\) Too long Consider the subtree calculating \ (A \) a \ (D1, D2, D3, CNT \) , calculates the number of words outside \ (B \) of \ (U1, U2 \) , and then discuss the classification

\(\text{Day1}\)

\ (T1 \)

No brain simulation

\ (T2 \)

Condensing the first point, then the point in the block can not be selected at the same time

For (the DAG \) \ , we consider the answer is block as \ (\ text {size} \ ) long chain, the longest way

\(\displaystyle{f_x=\max\{f_y\}+\text{size}_x}\)

\ (T3 \)

The smallest diameter of all the weights of the path path weight.
A first select each small two points m1, m2, and B for one of two small points b1, b2, calculate their shortest path m, b, and B will come up with small gems piles soul, has a pile a m, b has a another pile. A small pile and then start with a number of selected soul gems take the next small B to repeat the same operation, and so forth, until finally removed a soul gem, then removed the last man to win a precious stone.
Small B think this game is too simple, so he occasionally add some edge to this chart, in order to increase the difficulty of the game.
A little ability to predict the future, and she saw little to choose their own future in a B game, as well as a small increase in the B side. Now for each game, the small A would like to know whether the method to win their own existence. But predict the future she has consumed too much energy, out of exhaustion she had found you.

This question is found \ (Add \) operations rarely consider every violence

Let \ (Kruskal \) to build a \ (Mst \)

Each addition \ (A \ rightarrow B: V \) this edge,

If \ (V \ ge \) original tree path \ (A \ text {~} B \) maximum value, regardless

If \ (V <\) original tree path \ (A \ text {~} B \) maximum value, the maximum value is deleted, added this edge

Each reconstructed \ (ST \) table, the query is a path tree \ (A \ text {~} B \) maximum value to compare the

\ (The Tip: \) \ (ST \) requires only the \ (A \) or \ (B \) smaller depth down \ (DFS \) reconstruction, because the above does not change shape

inline void Findmax(re int x,re int y,re int fa,re int&pos,re int&flag){
    re int i;re ll maxx=-INF;flag=0;
    while(x!=fa){
        for(i=h[x];i;i=e[i].next)if(e[i].to==*dp[x]){if(del[i])continue;if(maxx<e[i].v){maxx=e[i].v;flag=1;pos=i;}}
        x=*dp[x];
    }
    while(y!=fa){
        for(i=h[y];i;i=e[i].next)if(e[i].to==*dp[y]){if(del[i])continue;if(maxx<e[i].v){maxx=e[i].v;flag=2;pos=i;}}
        y=*dp[y];
    }
}

(flag&1)?dfs_ST(y,*dp[y],dep[y]):dfs_ST(x,*dp[x],dep[x]);

\(\color{blue}{\text{Code}}\)

\(\text{Day2}\)

\ (T1 \)

Linear moving about the screen on it

inline void Prime(void){
    re int i,j;
    for(i=2;i<=maxx;++i){
        if(!vis[i])pri[++*pri]=i;
        for(j=1;j<=*pri;++j){
            if(i*pri[j]>maxx)break;
            vis[i*pri[j]]=(!vis[i])?2:1;
            if(!(i%pri[j]))break; 
        }
    }
    for(i=2;i<=maxx;++i)sum[i]=sum[i-1]+(!(vis[i]&1));
}

\ (T2 \)

Shaped key pressed state, a state where layered, shortest run to

\ (T3 \) (JZOJ5460)

Consider recording \ (6 \) values

\ (d1_x / d2_x / d3_x: x \) within the sub-tree \ (a \) is the largest / second largest strict / rigorous third-largest

\ (man_x \) represents \ (X \) the maximum value of the unique No subtree

\ (u1_x / u2_x: x \ ) outside the sub-tree \ (b \) is the largest / second largest strictly

\(ans=\begin{cases}d2_x&u1_x=0\\d1_x&man_x=1\\d1_x&d2_x+u1_x>d1_x\\d2_x+u1_x&d2_x+u1_x<d1_x\\\max\{d2_x+u2_x,d3_x+u1_x\}&d2_x+u1_x=d1_x\end{cases}\)

This process required amount of six (change \ (skr \) people)

inline void dfs(re int x,re int prt){//求d1,d2,d3,man 
    re int i,y;fa[x]=prt;
    d1[x]=a[x];d2[x]=-INF;d3[x]=-INF;dl1[x]=b[x];dl2[x]=-INF;
    cntd[x]=1;
    for(i=h[x];i;i=e[i].next){
        y=e[i].to;if(prt==y)continue;
        dfs(y,x);
        if(d1[x]<d1[y]){
            cntd[x]=cntd[y],d3[x]=d2[x];d2[x]=d1[x];d1[x]=d1[y];//严格次大值/第三大值 
        }
        else if(d1[x]==d1[y])cntd[x]+=cntd[y];
        else if(d2[x]<d1[y]){d3[x]=d2[x];d2[x]=d1[y];}
        else if(d3[x]<d1[y]&&d1[y]!=d2[x])d3[x]=d1[y];
        if(d2[x]<d2[y]&&d2[y]!=d1[x]){d3[x]=d2[x];d2[x]=d2[y];}
        else if(d3[x]<d2[y]&&d2[y]!=d2[x])d3[x]=d2[y];
        if(d3[x]<d3[y]&&d3[y]!=d2[x])d3[x]=d3[y];
        if(dl1[x]<dl2[y]){dl2[x]=dl1[x];dl1[x]=dl2[y];}
        else if(dl2[x]<dl2[y]&&dl2[y]!=dl1[x])dl2[x]=dl2[y];//只求严格次大值
        if(dl1[x]<dl1[y]){dl2[x]=dl1[x];dl1[x]=dl1[y];}
        else if(dl2[x]<dl1[y]&&dl1[y]!=dl1[x])dl2[x]=dl1[y];//只求严格次大值
    }
    if(cntd[x]>1)man[x]=1;
}
inline void Change(re int x){//求u1,u2
    re int i,j,pre=0,y,tim=1;tot=0;d[++tot]=(z){x,u1[x]};d[++tot]=(z){x,u2[x]};
    d[++tot]=(z){x,b[x]};
    for(i=h[x];i;i=e[i].next){
        y=e[i].to;if(fa[x]==y)continue;
        d[++tot]=(z){y,dl1[y]};d[++tot]=(z){y,dl2[y]};
    }
    sort(d+1,d+tot+1);
    for(i=h[x];i;i=e[i].next){
        y=e[i].to;if(fa[x]==y)continue;
        j=1;tim=1;pre=INF;u1[y]=u2[y]=-INF;
        while(tim<=2){
            for(;j<=tot;++j)if(d[j].pos!=y&&d[j].v!=pre)break;
            if(j>tot)break;
            if(tim==1)u1[y]=d[j].v;
            else u2[y]=d[j].v;
            ++tim;pre=d[j].v;
        }
    }
    for(i=h[x];i;i=e[i].next){y=e[i].to;if(fa[x]==y)continue;Change(y);}
}

Guess you like

Origin www.cnblogs.com/66t6/p/11785425.html