P4630 [APIO2018] Duathlon 铁人两项
2021-06-28 13:07
阅读:365
标签:pre www. new amp mat 完全 main ref problem
传送门
完全没想到圆方树orz……
我们先考虑建出这个图的圆方树,如果把方点的权值设为这个点双的大小,圆点的权值为\(-1\),那么起点\(s\)终点\(f\)的方案数就是这条路径上的权值总和,这样的话就可以做到\(O(n^2)\)
然后考虑用dfs优化,即计算每个点被经过了几次,那么就可以做到\(O(n)\)了
顺便注意起点和终点互换属于不同的方案,所以不要漏了
//minamoto
#include
#define ll long long
#define fp(i,a,b) for(register int i=a,I=b+1;iI;--i)
#define go(G,u) for(register int i=G.head[u],v=G.e[i].v;i;i=G.e[i].nx,v=G.e[i].v)
using namespace std;
inline int max(const int &x,const int &y){return x>y?x:y;}
inline int min(const int &x,const int &y){return x'9'||ch='0'&&ch=dfn[u]){
T.add(u,++tot),val[tot]=1;
do{
x=st[top--],T.add(tot,x);
sz[tot]+=sz[x],++val[tot];
}while(x!=v);
sz[u]+=sz[tot];
}
}
}
void dfs(int u){
if(u
P4630 [APIO2018] Duathlon 铁人两项
标签:pre www. new amp mat 完全 main ref problem
原文地址:https://www.cnblogs.com/bztMinamoto/p/10042202.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:P4630 [APIO2018] Duathlon 铁人两项
文章链接:http://soscw.com/essay/98905.html
文章标题:P4630 [APIO2018] Duathlon 铁人两项
文章链接:http://soscw.com/essay/98905.html
评论
亲,登录后才可以留言!