题解看这里 liouzhou_101的博客园 更简洁的代码看这里: #include <bits/stdc++.h> using namespace std; typedef long long LL; #define X first #define Y second inline void read(int &x) { int flag = 1; char ch; while(!isdigit(ch=getchar()))if(ch=='-')flag=-flag; for(x=0;…
Sasha and Interesting Fact from Graph Theory n 个 点形成 m 个有标号森林的方案数为 F(n, m) = m * n ^ {n - 1 - m} 然后就没啥难度了... #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #defin…
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules…
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1109D.html 题意 所有边权都是 [1,m] 中的整数的所有 n 个点的树中,点 a 到点 b 的距离恰好是 m 的有几个. $$n,m\leq 10^6$$ 题解 首先显然 a 和 b 的具体值是没用的. 于是我们就可以直接计数: 枚举树链 ab 上除了 a 和 b 有几个节点,假设是 i 个节点,那么这种情况下的方案总数是多少? 首先,ab 路径上 i+1 条 [1,m] 的边的和是 m ,共有…