QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#279285#7413. DeterminantDualqwqWA 2ms12364kbC++204.7kb2023-12-08 15:16:442023-12-08 15:16:44

Judging History

你现在查看的是最新测评结果

  • [2023-12-08 15:16:44]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12364kb
  • [2023-12-08 15:16:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace FastIO {
	#define iL (1 << 20)
	char ibuf[iL],*iS = ibuf + iL,*iT = ibuf + iL;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread(ibuf,1,iL,stdin),iS == iT ? EOF : *iS++) : *iS++)
	template<typename T>
	inline void read(T &a)
	{
		char ch;int sign = 0;
		for(ch = gc();!isdigit(ch);ch = gc())
			if(ch == '-') sign = 1;
		a = ch & 15;
		for(ch = gc();isdigit(ch);ch = gc())
			a = (a << 3) + (a << 1) + (ch & 15);
		if(sign) a = -a;
	}
	char Out[iL],*iter = Out;
	#define flush() fwrite(Out,1,iter - Out,stdout),iter = Out
	template<typename T>
	inline void write(T x,char end = '\n')
	{
		int c[40],l = 0;if(x < 0) *iter++ = '-',x = -x;
		do c[++l] = x % 10,x /= 10; while(x);
		while(l) *iter++ = c[l--] + '0';
		*iter++ = end;flush();
	}
	#undef iL 
	#undef gc
	#undef flush
}
using namespace FastIO;

const int N = 3e4 + 5,M = 1e6 + 5,K = 75,P = 998244353;
inline void Plus(int &x,const int &y) { x += y;if(x >= P) x -= P;}
inline int qpow(int a,int b) { int res = 1;while(b) { if(b&1) res = 1ll * res * a % P;a = 1ll * a * a % P;b >>= 1;} return res;}
int n,m,k;
int fir[N],nxt[M],to[M],ect = 1;
int dfn[N],low[N],cut[M],dfstime; // 把每个边双提出来
int e[K][K];
inline void addedge(int u1,int v1) {
	nxt[++ect] = fir[u1];fir[u1] = ect;to[ect] = v1;
}
inline int Det(int num) {
	static int A[K][K];
	for(int i = 1;i <= num;i++)
		for(int j = 1;j <= num;j++)
			A[i][j] = e[i][j];
	int ans = 1;
	for(int i = 1;i <= num;i++) {
		if(!A[i][i])
			for(int j = i + 1;j <= num;j++)
				if(A[j][i]) {
					for(int k = 1;k <= num;k++) swap(A[i][k],A[j][k]);
					ans = P - ans;break;
				}
		if(!A[i][i]) return 0;
		ans = 1ll * ans * A[i][i] % P;
		int inve = qpow(A[i][i],P - 2);
		for(int j = 1;j <= num;j++)
			if(j != i) {
				int div = 1ll * A[j][i] * inve % P;
				for(int k = i;k <= num;k++) Plus(A[j][k],P - 1ll * div * A[i][k] % P);
			}
	}
	return ans;
}
void tarjan(int x,int from) {
	dfn[x] = low[x] = ++dfstime;
	for(int i = fir[x],y;y = to[i],i;i = nxt[i]) 
		if(y != from) {
			if(!dfn[y]) {
				tarjan(y,x);
				low[x] = min(low[x],low[y]);
				if(low[y] > dfn[x]) cut[i] = cut[i ^ 1] = true;
			}
			else low[x] = min(low[x],dfn[y]);
		}
}
int co[N],dp[N][2];
vector<int> vs[N];
void dfs0(int x,int col) {
	co[x] = col;vs[col].push_back(x);
	// printf("co[%d]=%d\n",x,col);
	for(int i = fir[x],y;y = to[i],i;i = nxt[i])
		if(!co[y] && !cut[i]) dfs0(y,col);
}
int pre[N],suf[N];
int e2[K][K];
int c0[N];
void DP(int x,int fa) {
	int num = 2 * vs[x].size();
	int cnt = vs[x].size();
	for(int i = 1;i <= num;i++) for(int j = 1;j <= num;j++) e[i][j] = 0;
	for(int i = 0;i < vs[x].size();i++)
		for(int t = fir[vs[x][i]],j;j = to[t],t;t = nxt[t]) {
			auto pp = std::find(vs[x].begin(),vs[x].end(),j);
			if(pp != vs[x].end()) e[i + 1][pp - vs[x].begin() + 1]++;
		}
	for(int i = 0;i < vs[x].size();i++) {
		int u = vs[x][i];
		int s0 = 1,s1 = 0;
		vector<int> son;son.push_back(0);
		for(int t = fir[u],v;v = to[t],t;t = nxt[t]) {
			if(co[v] == fa || co[v] == x) continue;
			son.push_back(co[v]);DP(co[v],x);
			// printf("son:%d->%d\n",x,co[v]);
			s0 = 1ll * s0 * dp[co[v]][0] % P;
		}
		pre[0] = 1;
		for(int i = 1;i < son.size();i++)
			pre[i] = 1ll * pre[i - 1] * dp[son[i]][0] % P;
		suf[(int)son.size()] = 1;
		for(int i = (int)son.size() - 1;i >= 1;i--)
			suf[i] = 1ll * suf[i + 1] * dp[son[i]][0] % P;
		for(int i = 1;i < son.size();i++)
			Plus(s1,1ll * dp[son[i]][1] * pre[i - 1] % P * suf[i + 1] % P);
		int p1 = i + 1,p2 = i + vs[x].size() + 1;
		e[p2][p2] = s0;
		e[p1][p2] = s1;e[p2][p1] = 1;
		c0[u] = s0;
	}
	// printf("e: ");
	// for(int i = 1;i <= num;i++)
	// 	for(int j = 1;j <= num;j++)
	// 		printf("%d%c",e[i][j],j == num ? '\n' : ' ');
	dp[x][0] = Det(num);
	int psf = -1;
	for(int i = 0;i < cnt;i++)
		for(int t = fir[vs[x][i]],j;j = to[t],t;t = nxt[t])
			if(co[j] == fa) { psf = i + 1;break;}
	for(int i = 1;i <= num;i++)
		if(i != psf && i != psf + cnt)
		for(int j = 1;j <= num;j++) 
			if(j != psf && j != psf + cnt) {
			int p1 = i - (i >= psf) - (i >= psf + cnt);
			int p2 = j - (j >= psf) - (j >= psf + cnt);
			Plus(e2[p1][p2],e[i][j]);
		}
	num -= 2;
	for(int i = 1;i <= num;i++) for(int j = 1;j <= num;j++) e[i][j] = e2[i][j];
	dp[x][1] = 1ll * Det(num) * (psf > 0 ? c0[vs[x][psf - 1]] : 1) % P;
	// printf("dp[%d]=%d,%d\n",x,dp[x][0],dp[x][1]);
}
int main() {
	read(n);read(m);read(k);
	for(int i = 1;i <= m;i++) {
		int u,v;
		read(u);read(v);
		addedge(u,v);addedge(v,u);
	}
	tarjan(1,0);
	int col = 0;
	for(int i = 1;i <= n;i++) if(!co[i]) ++col,dfs0(i,col);
	DP(1,0);
	cout << dp[1][0] << endl;
	return 0;
}
/*
6 6 3
2 3
5 6
2 5
1 2
3 4
6 2
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10552kb

input:

4 3 1
1 2
2 3
3 4

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 10516kb

input:

6 6 3
2 3
5 6
2 5
1 2
3 4
6 2

output:

998244352

result:

ok 1 number(s): "998244352"

Test #3:

score: 0
Accepted
time: 1ms
memory: 10540kb

input:

10 15 10
1 8
1 7
6 7
2 8
6 9
1 2
4 9
4 10
4 6
5 6
3 8
9 10
8 10
3 5
2 7

output:

35

result:

ok 1 number(s): "35"

Test #4:

score: 0
Accepted
time: 0ms
memory: 10464kb

input:

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

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 1ms
memory: 8472kb

input:

1 0 1

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 1ms
memory: 11876kb

input:

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

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 12364kb

input:

10 12 3
3 5
5 9
5 10
1 2
1 3
2 3
4 5
4 6
5 6
7 8
7 9
8 9

output:

998244321

result:

wrong answer 1st numbers differ - expected: '4', found: '998244321'