QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#481240 | #7413. Determinant | Catluo | WA | 10ms | 81304kb | C++20 | 3.6kb | 2024-07-16 22:01:28 | 2024-07-16 22:01:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace IO{
char buff[1<<21],*p1=buff,*p2=buff;
char getch(){
return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
}
template<typename T>
void read(T &x){
char ch=getch();int fl=1;x=0;
while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
x*=fl;
}
template<typename T,typename ...Args>
void read(T &x,Args& ...args){
read(x);read(args...);
}
char obuf[1<<21],*p3=obuf;
void putch(char ch){
if(p3-obuf<(1<<21))*p3++=ch;
else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
}
char ch[100];
template<typename T>
void write(T x){
if(!x)return putch('0');
if(x<0)putch('-'),x*=-1;
int top=0;
while(x)ch[++top]=x%10+48,x/=10;
while(top)putch(ch[top]),top--;
}
template<typename T,typename ...Args>
void write(T x,Args ...args){
write(x);write(args...);
}
void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=25005,K=25,mod=998244353;
inline int Mod(int x){return x>=mod?x-mod:x;}
inline int poww(int x,int y){
int sum=1;
while(y){
if(y&1)sum=1ll*sum*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return sum;
}
int n,m,MAXNK,Num;
struct graph{
vector<int>id;
int to[K][K];
vector<int>t[K];
}BCC[N];
int color[N],Wid[N];
vector<int>to[N];
int f[N][2],g[N][2];
int dfn[N],stk[N],low[N],top,dfs_clock;
void tarjan(int i,int fa){
// cout<<fa<<"->"<<i<<'\n';
low[i]=dfn[i]=++dfs_clock;
stk[++top]=i;
for(auto j:to[i]){
if(j==fa)continue;
if(dfn[j]==0)tarjan(j,i), low[i]=min(low[i],low[j]);
else low[i]=min(low[i],dfn[j]);
}
if(low[i]==dfn[i]){
Num++;
while(1){
int x=stk[top--];
color[x]=Num;
Wid[x]=BCC[Num].id.size();
BCC[Num].id.push_back(x);
if(x==i) break;
}
}
}
int det(int a[K][K],int len){
int ans=1;
for(int i=0;i<len;i++){
int id=-1;
for(int j=i;j<len;j++)if(a[j][i]){id=j;break;}
if(id==-1)return 0;
if(id!=i)ans=mod-ans;
swap(a[i],a[id]);
int Inv=poww(a[i][i],mod-2);
for(int j=i+1;j<len;j++){
int s=mod-1ll*a[j][i]*Inv%mod;
for(int k=i;k<len;k++)a[j][k]=Mod(a[j][k]+1ll*a[i][k]*s%mod);
}
}
for(int i=0;i<len;i++)ans=1ll*ans*a[i][i]%mod;
return ans;
}
void calc(int X,int fa){
int rt=1,len=BCC[X].id.size();
for(auto x:BCC[X].id){
g[x][0]=1;
for(auto y:to[x]){
if(color[x]==color[y]){
BCC[X].to[Wid[x]][Wid[y]]=BCC[X].to[Wid[y]][Wid[x]]=1;
}else{
if(color[y]==fa)rt=x;
else{
calc(color[y],X);
g[x][1]=Mod(1ll*g[x][1]*f[y][1]%mod+1ll*g[x][0]*f[color[y]][0]%mod);
g[x][0]=1ll*g[x][0]*f[color[y]][1]%mod;
}
}
}
}
int b[K][K],c[K][K];
memcpy(b,BCC[X].to,sizeof BCC[X].to);
for(int i=0;i<len;i++){
for(int j=0;j<len;j++){
if(i==j)b[i][j]=g[BCC[X].id[i]][1];
else b[i][j]=1ll*b[i][j]*g[BCC[X].id[i]][0]%mod;
}
}
memcpy(c,b,sizeof b);
f[X][1]=det(b,len);
rt=Wid[rt];
for(int i=0;i<len;i++)c[i][rt]=c[rt][i]=0;
for(int i=0;i<len;i++) for(int j=0;j<len;j++){
if(i<rt&&j<rt)continue;
if(i<rt)c[i][j]=c[i][j+1];
else if(j<rt) c[i][j]=c[i+1][j];
else c[i][j]=c[i+1][j+1];
}
f[X][0]=det(c,len-1);
}
signed main(){
read(n,m,MAXNK);
for(int i=1;i<=m;i++){
int x,y;
read(x,y);
to[x].push_back(y);
to[y].push_back(x);
}
tarjan(1,0);
calc(Num,0);
write(f[Num][1]);
flush();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 80240kb
input:
4 3 1 1 2 2 3 3 4
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 80840kb
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: 10ms
memory: 81304kb
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: 80040kb
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: 4ms
memory: 80088kb
input:
1 0 1
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 4ms
memory: 80084kb
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: 3ms
memory: 80088kb
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:
998244350
result:
wrong answer 1st numbers differ - expected: '4', found: '998244350'