QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#792159#9278. Linear Algebra Intensifiesbulijiojiodibuliduo#WA 4ms35684kbC++175.2kb2024-11-29 02:07:402024-11-29 02:07:41

Judging History

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

  • [2024-11-29 02:07:41]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:35684kb
  • [2024-11-29 02:07:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

template<int MOD, int RT> struct mint {
	static const int mod = MOD;
	static constexpr mint rt() { return RT; } // primitive root for FFT
	int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
	mint():v(0) {}
	mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
		if (v < 0) v += MOD; }
	bool operator==(const mint& o) const {
		return v == o.v; }
	friend bool operator!=(const mint& a, const mint& b) { 
		return !(a == b); }
	friend bool operator<(const mint& a, const mint& b) { 
		return a.v < b.v; }
   
	mint& operator+=(const mint& o) { 
		if ((v += o.v) >= MOD) v -= MOD; 
		return *this; }
	mint& operator-=(const mint& o) { 
		if ((v -= o.v) < 0) v += MOD; 
		return *this; }
	mint& operator*=(const mint& o) { 
		v = int((ll)v*o.v%MOD); return *this; }
	mint& operator/=(const mint& o) { return (*this) *= inv(o); }
	friend mint pow(mint a, ll p) {
		mint ans = 1; assert(p >= 0);
		for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans; }
	friend mint inv(const mint& a) { assert(a.v != 0); 
		return pow(a,MOD-2); }
		
	mint operator-() const { return mint(-v); }
	mint& operator++() { return *this += 1; }
	mint& operator--() { return *this -= 1; }
	friend mint operator+(mint a, const mint& b) { return a += b; }
	friend mint operator-(mint a, const mint& b) { return a -= b; }
	friend mint operator*(mint a, const mint& b) { return a *= b; }
	friend mint operator/(mint a, const mint& b) { return a /= b; }
};

const int MOD=998244353; 
using mi = mint<MOD,5>; // 5 is primitive root for both common mods

namespace simp {
	vector<mi> fac,ifac,invn;
	void check(int x) {
		if (fac.empty()) {
			fac={mi(1),mi(1)};
			ifac={mi(1),mi(1)};
			invn={mi(0),mi(1)};
		}
		while (SZ(fac)<=x) {
			int n=SZ(fac),m=SZ(fac)*2;
			fac.resize(m);
			ifac.resize(m);
			invn.resize(m);
			for (int i=n;i<m;i++) {
				fac[i]=fac[i-1]*mi(i);
				invn[i]=mi(MOD-MOD/i)*invn[MOD%i];
				ifac[i]=ifac[i-1]*invn[i];
			}
		}
	}
	mi gfac(int x) {
		assert(x>=0);
		check(x); return fac[x];
	}
	mi ginv(int x) {
		assert(x>0);
		check(x); return invn[x];
	}
	mi gifac(int x) {
		assert(x>=0);
		check(x); return ifac[x];
	}
	mi binom(int n,int m) {
		if (m < 0 || m > n) return mi(0);
		return gfac(n)*gifac(m)*gifac(n - m);
	}
	mi binombf(int n,int m) {
		if (m < 0 || m > n) return mi(0);
		if (m>n-m) m=n-m;
		mi p=1,q=1;
		for (int i=1;i<=m;i++) p=p*(n+1-i),q=q*i;
		return p/q;
	}
}


const int N=501000;
int f[N],n,m,id[N];
set<PII> e[N];
mi g[1111][1111];

mi det(vector<vector<mi>> f) {
	int n=SZ(f);
	mi ans=1;
	rep(i,0,n) {
		bool fg=0;
		rep(j,i,n) {
			if (f[j][i]!=0) {
				rep(k,i,n) swap(f[i][k],f[j][k]);
				if (j!=i) ans*=-1;
				fg=1;
				break;
			}
		}
		if (!fg) return 0;
		mi v=1/(-f[i][i]);
		rep(j,i+1,n) {
			mi tmp=f[j][i]*v;
			rep(k,i,n) f[j][k]=(f[j][k]+tmp*f[i][k]);
		}
	}
	rep(i,0,n) ans=ans*f[i][i];
	return ans;
}

int find(int x) {
	return f[x]==x?x:f[x]=find(f[x]);
}
int main() {
	scanf("%d%d",&n,&m);
	rep(i,0,n+1) f[i]=i;
	rep(i,0,m) {
		int u,v;
		scanf("%d%d",&u,&v);
		--u;
		f[find(u)]=find(v);
		e[u].insert(mp(v,i));
		e[v].insert(mp(u,i));
	}
	rep(i,0,n+1) if (find(i)!=find(0)) {
		puts("0");
		return 0;
	}
	if (m==n) {
		puts("1");
		return 0;
	}
	queue<int> q;
	rep(i,0,n+1) {
		if (SZ(e[i])==1) q.push(i);
	}
	while (!q.empty()) {
		auto u=q.front(); q.pop();
		auto [v,w]=*e[u].begin();
		assert(e[v].count(mp(u,w)));
		e[v].erase(mp(u,w));
		e[u].clear();
		if (SZ(e[v])==1) {
			q.push(v);
		}
	}
	VI pv;
	int c2=0;
	rep(i,0,n+1) {
		if (SZ(e[i])>=3) {
			pv.pb(i);
			id[i]=SZ(pv);
		}
		if (SZ(e[i])==2) c2++;
	}
	if (pv.empty()) {
		printf("%d\n",c2);
		return 0;
	}
	mi ans=1;
	VI selfv;
	auto addeg=[&](int u,int v,int w) {
		u=id[u]-1; v=id[v]-1;
		if (u==v) {
			selfv.pb(w);
			return;
		}
		ans=ans*w;
		//printf("%d %d %d\n",u,v,w);
		mi iw=mi(1)/mi(w);
		g[u][u]+=iw;
		g[u][v]-=iw;
	};
	function<void(int,int,int,int)> dfs=[&](int u,int par,int dep,int rt) {
		if (dep>0&&id[u]) {
			addeg(rt,u,dep);
			return;
		}
		for (auto [v,w]:e[u]) if (w!=par) {
			dfs(v,w,dep+1,rt);
		}
	};
	for (auto u:pv) dfs(u,-1,0,u);
	//printf("%d\n",(int)ans);
	vector<vector<mi>> ff;
	rep(i,1,SZ(pv)) ff.pb(vector<mi>(g[i]+1,g[i]+SZ(pv)));
	ans=ans*det(ff);
	sort(all(selfv));
	//for (auto x:selfv) printf("%d ",x); puts("");
	for (int i=0;i<SZ(selfv);i+=2) ans=ans*selfv[i];
	printf("%d\n",(int)ans);
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 35076kb

input:

3 4
1 2
2 3
1 2
3 3

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 4ms
memory: 34440kb

input:

1 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

1 10
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

output:

10

result:

ok 1 number(s): "10"

Test #4:

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

input:

2 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #5:

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

input:

2 2
1 2
1 1

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 2ms
memory: 34568kb

input:

2 3
1 1
2 2
1 2

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 35684kb

input:

12 23
10 12
6 12
3 6
3 4
5 12
10 10
10 11
9 9
8 12
4 12
1 9
4 9
2 2
10 11
5 12
8 12
9 9
1 9
6 12
10 10
2 2
3 6
3 4

output:

6144

result:

wrong answer 1st numbers differ - expected: '3072', found: '6144'