QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#588385 | #9278. Linear Algebra Intensifies | zjy0001 | WA | 3ms | 23640kb | C++17 | 1.9kb | 2024-09-25 10:13:03 | 2024-09-25 10:13:12 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
typedef vector<int> Vec;
typedef vector<Vec> Mat;
const int N=5e5+5,Mod=998244353;
int n,m,An;
vector<int>G[N];
vector<tuple<int,int,int>>E;
int fd[N],A[N],id[N],nxt[N],D[N];
inline int qpow(int x,int y,int z=1){
for(;y;(y>>=1)&&(x=(LL)x*x%Mod))if(y&1)z=(LL)z*x%Mod;return z;
}
inline int Det(Mat A){
const int n=A.size();int z=1;
for(int i=0;i<n;++i)
for(int j=i+1;j<n;++j){
while(A[i][i]){
const int v=A[j][i]/A[i][i];
for(int k=i;k<n;++k)
A[j][k]=(A[j][k]-1ll*v*A[i][k])%Mod;
A[i].swap(A[j]),z=-z;
}
A[i].swap(A[j]),z=-z;
}
for(int i=0;i<n;++i)z=1ll*z*A[i][i]%Mod;
return z<0?z+Mod:z;
}
inline int find(const int&x){
return x==fd[x]?x:fd[x]=find(fd[x]);
}
inline void dfs(int u,int fa){
D[u]=D[fa]+1;
int ch=0,r=0;
for(auto v:G[u])if(v!=fa){
dfs(v,u);
if(nxt[v])++ch,r=nxt[v];
}
if(ch>1||id[u]){
id[u]=1;
for(auto v:G[u])if(v!=fa&&nxt[v])
E.emplace_back(u,nxt[v],D[nxt[v]]-D[u]);
nxt[u]=u;
}
else nxt[u]=r;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m,++n;
iota(fd+1,fd+n+1,1);
for(int i=1;i<=m;++i){
int u,v;cin>>u>>v,++v;
if(find(u)!=find(v)){
G[u].emplace_back(v);
G[v].emplace_back(u);
fd[find(u)]=find(v);
}
else{
id[u]=id[v]=1;
E.emplace_back(u,v,1);
}
}
for(int i=1;i<=n;++i)if(find(i)!=find(1))return cout<<"0\n",0;
if(E.empty())return cout<<"1\n",0;
dfs(1,0);
for(int i=1;i<=n;++i)id[i+1]+=id[i];
Mat Q(id[n],Vec(id[n]));
for(auto [u,v,w]:E)
u=id[u]-1,v=id[v]-1,
Q[u][v]-=w,Q[v][u]-=w,Q[u][u]+=w,Q[v][v]+=w;
Q.pop_back();
for(auto&i:Q)i.pop_back();
cout<<Det(Q)<<'\n';
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 22184kb
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: 0ms
memory: 18996kb
input:
1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 23640kb
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: 3ms
memory: 19244kb
input:
2 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 17436kb
input:
2 2 1 2 1 1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 22624kb
input:
2 3 1 1 2 2 1 2
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 3ms
memory: 23308kb
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:
3072
result:
ok 1 number(s): "3072"
Test #8:
score: 0
Accepted
time: 2ms
memory: 23296kb
input:
2 10 1 2 2 2 1 1 1 1 1 2 1 1 1 2 2 2 2 2 1 2
output:
33
result:
ok 1 number(s): "33"
Test #9:
score: 0
Accepted
time: 0ms
memory: 22600kb
input:
9 20 4 6 9 9 8 9 3 3 2 8 6 8 9 9 2 6 2 8 1 1 2 4 1 2 5 9 1 3 2 7 1 3 1 6 2 3 2 8 2 6
output:
3696
result:
ok 1 number(s): "3696"
Test #10:
score: 0
Accepted
time: 2ms
memory: 22288kb
input:
109 245 6 57 29 81 21 76 21 76 36 44 53 71 29 29 43 78 1 12 26 50 3 100 8 84 30 103 1 21 61 76 19 78 37 55 78 79 15 64 18 53 40 82 28 66 14 40 30 63 53 85 64 106 1 95 87 106 14 36 8 84 30 64 40 82 9 62 29 50 68 87 48 64 63 105 1 17 15 66 26 50 1 48 50 75 52 75 10 10 74 106 9 75 65 102 91 103 12 83 6...
output:
589921054
result:
ok 1 number(s): "589921054"
Test #11:
score: 0
Accepted
time: 0ms
memory: 18816kb
input:
100 100 46 100 45 92 86 97 72 78 44 79 35 97 31 92 88 93 49 89 12 56 7 63 58 86 51 70 81 100 33 37 29 94 12 38 31 53 26 90 77 96 10 88 26 69 44 90 6 48 37 47 60 77 32 42 40 41 50 83 83 90 95 100 21 33 17 62 12 91 59 68 63 82 11 60 48 98 5 47 56 60 1 95 38 52 25 66 51 59 4 33 95 96 55 74 26 93 25 68 ...
output:
1
result:
ok 1 number(s): "1"
Test #12:
score: -100
Wrong Answer
time: 0ms
memory: 22520kb
input:
122 123 4 37 48 73 21 96 68 84 43 94 11 36 38 113 40 108 65 81 10 111 6 19 80 92 37 40 40 122 60 113 2 19 29 31 26 75 33 68 27 69 51 65 17 90 88 112 56 68 46 46 83 110 25 80 14 38 101 108 16 41 64 89 19 88 76 87 26 79 51 90 107 119 7 17 71 100 17 59 14 105 15 26 22 95 113 117 22 91 19 99 57 119 42 5...
output:
1034
result:
wrong answer 1st numbers differ - expected: '123', found: '1034'