当前位置:网站首页>Luogu p5406 [thupc2019] find tree
Luogu p5406 [thupc2019] find tree
2022-06-22 08:37:00 【lahlah_】
https://www.luogu.com.cn/problem/P5406
First of all, realize that this problem is not an optimization problem , It's a counting problem ( This alone is not simple )
Consider what the matrix tree theorem calculates
∑ T ∏ w e ∈ T \sum_{T}\prod w_{e\in T} T∑∏we∈T
here ∏ \prod ∏ Not necessarily multiplication , These operations given in the title can
So we can construct set power series x w x^{w} xw, be aware F W T FWT FWT It's a linear operation , Can stack , First F W T FWT FWT End , Find a determinant , And then again I D F T IDFT IDFT Just go back
code:
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;
const int N = (1 << 12) + 5;
const int inv2 = (mod + 1) / 2;
char st[15];
void fwt(ll *a, int n, int o) {
for(int len = 2, pos = 1; len <= n; len <<= 1, pos ++) {
if(st[pos] == '|') {
for(int j = 0; j < n; j += len)
for(int k = j; k < j + (len >> 1); k ++)
a[k + (len >> 1)] = (a[k + (len >> 1)] + o * a[k] + mod) % mod;
}
if(st[pos] == '&') {
for(int j = 0; j < n; j += len)
for(int k = j; k < j + (len >> 1); k ++)
a[k] = (a[k] + o * a[k + (len >> 1)] + mod) % mod;
}
if(st[pos] == '^') {
for(int j = 0; j < n; j += len)
for(int k = j; k < j + (len >> 1); k ++) {
int X = a[k], Y = a[k + (len >> 1)];
a[k] = (X + Y) % mod, a[k + (len >> 1)] = (X - Y + mod) % mod;
if(o == -1) a[k] = a[k] * inv2 % mod, a[k + (len >> 1)] = a[k + (len >> 1)] * inv2 % mod;
}
}
}
}
ll qpow(ll x, ll y) {
ll ret = 1;
for(; y; y >>= 1, x = x * x % mod) if(y & 1) ret = ret * x % mod;
return ret;
}
ll a[75][75];
ll DET(int n) {
ll ans = 1;
for(int i = 1; i <= n; i ++) {
int j = i;
for(int k = i + 1; k <= n; k ++) if(a[k][i]) j = k;
if(j != i) {
ans = (mod - ans);
swap(a[i], a[j]);
}
if(!a[i][i]) return 0;
for(int j = i + 1; j <= n; j ++) {
ll t = a[j][i] * qpow(a[i][i], mod - 2) % mod;
for(int k = i; k <= n; k ++) {
a[j][k] = (a[j][k] - t * a[i][k] % mod + mod) % mod;
}
}
}
for(int i = 1; i <= n; i ++) ans = ans * a[i][i] % mod;
return ans;
}
int n, m, w, lim;
ll in[75][75][N], ans[N];
int main() {
scanf("%d%d", &n, &m);
scanf("%s", st + 1);
w = strlen(st + 1);
lim = (1 << w);
for(int i = 1; i <= m; i ++) {
int u, v, c;
scanf("%d%d%d", &u, &v, &c);
in[u][v][c] --, in[v][u][c] --;
in[u][u][c] ++, in[v][v][c] ++;
}
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
for(int k = 0; k < lim; k ++)
in[i][j][k] = (in[i][j][k] + mod) % mod;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
fwt(in[i][j], lim, 1);
for(int c = 0; c < lim; c ++) {
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
a[i][j] = in[i][j][c];
ans[c] = DET(n - 1);
}
fwt(ans, lim, -1);
for(int i = lim - 1; i >= 0; i --) {
if(ans[i]) {
printf("%d", i); return 0;}
}
printf("-1");
return 0;
}
边栏推荐
- The role of subject integration in steam Education
- 邮件巨头曝严重漏洞,用户数据被窃取
- Some problems encountered in using swagger in golang
- Flask blog practice - realize article management
- Spark Yarn内存资源计算分析(参考)--Executor Cores、Nums、Memory优化配置
- Powerful database design tool PowerDesigner
- Multi tenancy and Implementation
- 解读创客教育中的技术一族
- Flask博客实战 - 使用 WTForms 进行表单验证
- Enumerations, custom types, and swaggerignore in swagger
猜你喜欢
随机推荐
10.File/IO流-bite
Chapter VIII web project testing (the end of this chapter)
MySQL sub database and sub table
Bit group sort
Define the data source of hikaricp connection pool for bee
同态加密的基本概念
Flask blog practice - realize the classified management of blogs
Third party services (file and picture storage)
Basic concepts of homomorphic encryption
Matplotlib | temperature change visualization
YOLOv5报错:AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘ 的解决方案
中断中为何不能使用信号量,中断上下文为何不能睡眠
Yolov5 reports an error: attributeerror: 'upsample' object has no attribute 'recommend_ scale_ Solution of 'factor'
Object to string pit
电机学感应电动机重点知识总结(现有题目中反映的)
报告:在技术领域,男性更有可能获得工作面试的机会
The challenge of image based voice processing in real-time audio and video -- RTC dev Meetup
The role of subject integration in steam Education
Any to Any 实时变声的实现与落地丨RTC Dev Meetup
15 命令模式







![luogu P4292 [WC2010]重建计划](/img/09/5417e0b62e5205c4dabf4571823492.png)

