$$\color{#0066ff}{ 题目描述 }$$

leizi决定找出两个pwang并把他们按在床上揍。leizi希望选择的方案恰好被c个人支持，一个oier会支持一个方案当且仅当至少有一个他认为的pwang被leizi揍了。

$$\color{#0066ff}{输入样例}$$

8
5 6
5 7
5 8
6 2
2 1
7 3
1 3
1 4

$$\color{#0066ff}{输出样例}$$

0
0
1
12
10
4
1
0
0

IAKNOI

28

$$\color{#0066ff}{ 题解 }$$

这启示我们对mp开桶，设为t

\begin{aligned} ans[v]=\sum_{mp_i+mp_j=v}t_{mp_i}*t_{mp_j}\end{aligned}

最后别忘考虑那些存在s的东西

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cctype>
#include<vector>
#include<cmath>
#define LL long long

LL in() {
char ch; LL x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
namespace qwq {
void in() {
freopen("leigehhh.in", "r", stdin);
freopen("leigehhh.out", "w", stdout);
}
void out() {
fclose(stdin);
fclose(stdout);
}
}
using std::vector;
const int maxn = 1e5 + 100;
const double pi = acos(-1);
int t[maxn], mp[maxn];
LL tt[maxn], lst[maxn], ans[maxn];
vector<int> v[maxn];
struct node {
double x, y;
node(double x = 0, double y = 0): x(x), y(y) {}
friend node operator + (const node &a, const node &b) { return node(a.x + b.x, a.y + b.y); }
friend node operator - (const node &a, const node &b) { return node(a.x - b.x, a.y - b.y); }
friend node operator * (const node &a, const node &b) { return node(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
friend node operator / (const node &a, const double &b) { return node(a.x / b, a.y / b); }
}A[maxn], B[maxn], C[maxn];
int len, r[maxn];
void FFT(node *D, int flag) {
for(int i = 0; i < len; i++) if(i < r[i]) std::swap(D[i], D[r[i]]);
for(int l = 1; l < len; l <<= 1) {
node w0(cos(pi / l), flag * sin(pi / l));
for(int i = 0; i < len; i += (l << 1)) {
node w(1, 0), *a0 = D + i, *a1 = D + i + l;
for(int k = 0; k < l; k++, a0++, a1++, w = w * w0) {
node tmp = *a1 * w;
*a1 = *a0 - tmp;
*a0 = *a0 + tmp;
}
}
}
if(!(~flag)) for(int i = 0; i < len; i++) D[i] = D[i] / len;
}
int main() {
freopen("leigehhh.in", "r", stdin);
freopen("leigehhh.out", "w", stdout);
int n = in();
int x, y;
for(int i = 1; i <= n; i++) {
x = in(), y = in();
v[x].push_back(y);
v[y].push_back(x);
mp[x]++, mp[y]++;
}
for(int i = 1; i <= n; i++) {
std::sort(v[i].begin(), v[i].end());
for(int j = 0; j < (int)v[i].size(); j++) t[v[i][j]]++;
for(int j = 0; j < (int)v[i].size(); j++) {
if(j && v[i][j] == v[i][j - 1]) continue;
ans[mp[i] + mp[v[i][j]]]--;
ans[mp[i] + mp[v[i][j]] - t[v[i][j]]]++;
t[v[i][j]] = 0;
}
}
for(int i = 1; i <= n; i++) tt[mp[i]]++;
for(int i = 0; i <= n; i++) B[i] = A[i] = tt[i];
for(len = 1; len <= n + n; len <<= 1);
for(int i = 0; i < len; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) * (len >> 1));
FFT(A, 1), FFT(B, 1);
for(int i = 0; i < len; i++) C[i] = A[i] * B[i];
FFT(C, -1);
for(int i = 0; i <= n; i++) lst[i] = (int)round(C[i].x);
for(int i = 0; i <= n; i++) {
if(i & 1) continue;
lst[i] -= tt[i >> 1] * tt[i >> 1];
lst[i] += (tt[i >> 1] * (tt[i >> 1] - 1LL));
}
for(int i = 0; i <= n; i++) printf("%lld\n", (ans[i] >> 1LL) + (lst[i] >> 1LL));
return 0;
}

0条评论