随笔分类 -  模板

摘要:#include #include #include #include #include #include #define ll long long using namespace std; ll n,p; int main() { scanf("%lld%lld",&n,&p); ll a=n,ans=1,b=p-2; while(b) { if... 阅读全文
posted @ 2018-07-08 16:59 radishえらい 阅读(146) 评论(0) 推荐(0)
摘要://带偏移量的并查集≈并查集补集 //维护各点到父节点的距离 可用来分类 #include #include #include #include #include #include using namespace std; int n,f[1001],d[1001]; int find(int x) { if(x==f[x]) return x; d[x]+=... 阅读全文
posted @ 2018-07-08 16:58 radishえらい 阅读(288) 评论(0) 推荐(0)
摘要://Tarjan 强连通分量 //dfn[]时间戳 low[]经过一条非回溯边可到达的时间戳最小节点 即其能回溯到的最小节点 #include #include #include #include #include #include using namespace std; int n,m,cnt,head[10001]; int t,sta[10001],vis[10001]; int d... 阅读全文
posted @ 2018-07-08 16:55 radishえらい 阅读(130) 评论(0) 推荐(0)
摘要://tarjan 缩点 //把强连通分量染成同样的颜色 用数组记录一下强连通分量内所有点权和 #include #include #include #include #include #include using namespace std; int n,m,cnt,ans,head[10001]; int t,sta[10001],vis[10001]; int dot,dfn[10001... 阅读全文
posted @ 2018-07-08 16:55 radishえらい 阅读(160) 评论(0) 推荐(0)
摘要://Tarjan 割边 //当dfn[u] #include #include #include #include #include using namespace std; int n,m,cnt,ans,head[10001]; int dot,dfn[10001],low[10001]; int cut[200001]; struct uio{ int from,to,next,... 阅读全文
posted @ 2018-07-08 16:54 radishえらい 阅读(151) 评论(0) 推荐(0)
摘要://Tarjan 割点 //根节点满足子节点个数>=2即为割点 //非根节点满足dfn[u] #include #include #include #include #include using namespace std; int n,m,cnt,ans,head[100001]; int dot,dfn[100001],low[100001]; int cut[100001]; stru... 阅读全文
posted @ 2018-07-08 16:54 radishえらい 阅读(286) 评论(0) 推荐(0)
摘要://ST表 //计算RMQ 即区间最值 //思想:区间dp+倍增 //注:将代码内所有max改成min即可求最小值 #include #include #include #include #include #include using namespace std; int n,m,l,r,a[100001]; int Pow[31],Log[100001];//Pow[i]表示2的i次幂 L... 阅读全文
posted @ 2018-07-08 16:53 radishえらい 阅读(121) 评论(0) 推荐(0)
摘要://LCA //树链剖分 在线 #include #include #include #include #include #include using namespace std; int n,m,root,cnt,head[500001]; int hvyson[500001],fa[500001],siz[500001],dep[500001],top[500001]; struct ui... 阅读全文
posted @ 2018-07-08 16:52 radishえらい 阅读(108) 评论(0) 推荐(0)
摘要://LCA //倍增 在线 #include #include #include #include #include #include #define maxn 500001 using namespace std; int n,m,root,cnt; int head[2*maxn],depth[maxn],f[maxn][21];//depth深度 f[a][b]指a节点的第2^b个祖先 ... 阅读全文
posted @ 2018-07-08 16:51 radishえらい 阅读(115) 评论(0) 推荐(0)
摘要://LCA //Tarjan 离线 #include #include #include #include #include #include #define maxn 500001 using namespace std; int n,m,root,cnt,lca[maxn],head[maxn],jdg[maxn],fa[maxn],set[maxn];//set并查集 int cntg... 阅读全文
posted @ 2018-07-08 16:50 radishえらい 阅读(95) 评论(0) 推荐(0)
摘要://LCA //ST表 在线 #include #include #include #include #include #include #define maxn 500001 using namespace std; int n,m,cnt,root,head[maxn],depth[maxn]; int order[2*maxn],first[maxn];//order[x]dfs中第x次... 阅读全文
posted @ 2018-07-08 16:49 radishえらい 阅读(318) 评论(0) 推荐(0)