QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#481512 | #7413. Determinant | Catluo | WA | 8ms | 80836kb | C++14 | 3.8kb | 2024-07-17 08:00:36 | 2024-07-17 08:00:38 |
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,g[x][1]=0;
for(auto y:to[x]){
if(X==color[y]){
BCC[X].to[Wid[x]][Wid[y]]++;
}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;
}
}
}
cout<<x<<':'<<g[x][0]<<' '<<g[x][1]<<'\n';
}
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);
b[rt][rt]=0;
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);
// cout<<Num<<'\n';
// for(int i=1;i<=Num;i++){
// cout<<i<<":\n";
// for(auto j:BCC[i].id)
// cout<<j<<' ';cout<<'\n';
// }
calc(Num,0);
write(f[Num][1]);
flush();
return 0;
}/*
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 80836kb
input:
4 3 1 1 2 2 3 3 4
output:
4:1 0 3:0 1 2:1 1 1:1 1 1
result:
wrong output format Expected integer, but "4:1" found