QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#386433 | #4654. Tree | dengtingyu | WA | 743ms | 11304kb | C++14 | 3.5kb | 2024-04-11 16:37:05 | 2024-04-11 16:37:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll yu=1e9+7;
inline ll ksm(ll x,ll y=yu-2){
ll an=1;for(;y;y>>=1){
if(y&1)an=an*x%yu;
x=x*x%yu;
}return an;
}
struct juz{
vector<vector<ll> >a;
ll n,m;
juz(ll x,ll y){n=x;m=y;a.resize(x);for(auto &o:a)o.resize(y);return ;}
inline juz extend(vector<ll>b)const{
juz nw(n,m+1);
for(int i=0;i<n;i++)for(int j=0;j<m;j++)nw.a[i][j]=a[i][j];
for(int j=0;j<n;j++)nw.a[j][m]=b[j];
return nw;
}
inline juz zt()const{
juz nw(m,n);
for(int i=0;i<n;i++)for(int j=0;j<m;j++)nw.a[j][i]=a[i][j];
return nw;
}
inline juz mvr(ll x)const{
juz nw(n-1,m);ll cn=0;
for(int i=0;i<n;i++){
if(i==x)continue;
for(int j=0;j<m;j++)nw.a[cn][j]=a[i][j];cn++;
}return nw;
}
inline juz mvc(ll x)const{
juz nw(n,m-1);ll cn=0;
for(int i=0;i<m;i++){
if(i==x)continue;
for(int j=0;j<n;j++)nw.a[j][cn]=a[j][i];cn++;
}return nw;
}
inline ll det()const{
ll ans=1,f=0;juz nw=*this;
for(int i=0;i<n;i++){
ll pos=i;for(int j=i+1;j<n;j++)if(nw.a[pos][i]<nw.a[j][i])pos=j;
if(pos!=i)swap(nw.a[i],nw.a[pos]),f^=1;ans=ans*nw.a[i][i]%yu;
if(!nw.a[i][i])continue;ll tem=ksm(nw.a[i][i]);
for(int j=i+1;j<n;j++){
ll tt=(yu-tem)*nw.a[j][i]%yu;
for(int k=i;k<n;k++)nw.a[j][k]=(nw.a[j][k]+tt*nw.a[i][k])%yu;
}
}if(f)ans=(yu-ans)%yu;
return ans;
}
inline vector<ll> gs(vector<ll>x)const{
juz nw=this->extend(x);
for(int i=0;i<n;i++){
ll pos=i;for(int j=i+1;j<n;j++)if(nw.a[pos][i]<nw.a[j][i])pos=j;
if(pos!=i)swap(nw.a[i],nw.a[pos]);if(!nw.a[i][i])continue;
ll tem=ksm(nw.a[i][i]);
for(int j=i;j<m+1;j++)nw.a[i][j]=nw.a[i][j]*tem%yu;
for(int j=0;j<n;j++){
if(j==i)continue;ll tem=yu-nw.a[j][i];
for(int k=i;k<m+1;k++)nw.a[j][k]=(nw.a[j][k]+tem*nw.a[i][k])%yu;
}
}for(int i=0;i<n;i++){
if(nw.a[i][i])continue;
vector<ll>an(m,0);an[i]=1;
for(int j=0;j<n;j++){
if(i!=j){
an[j]=(yu-nw.a[j][i])%yu;
}
}return an;
}vector<ll>tem(m,0);return tem;
}
};
ll n,m;
int main(){
// freopen("test1.in","r",stdin);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll ti;cin>>ti;while(ti--){
cin>>n>>m;if(n==1){cout<<1<<'\n';continue;}
juz a(n,n);
for(int i=1;i<=m;i++){
ll u,v;cin>>u>>v;u--;v--;
a.a[v][v]=(a.a[v][v]+1)%yu;a.a[u][v]=(a.a[u][v]+yu-1)%yu;
}vector<ll>tem(n,0);
vector<ll>x=a.gs(tem);//for(auto o:x)cout<<o<<' ';cout<<'\n';continue;
vector<ll>y=a.zt().gs(tem);//for(auto o:y)cout<<o<<' ';cout<<'\n';
ll px=x.size();for(int i=0;i<x.size();i++)if(x[i]){px=i;break;}
ll py=y.size();for(int i=0;i<y.size();i++)if(y[i]){py=i;break;}
ll an=a.mvr(px).mvc(py).det();
if((px+py)&1)an=(yu-an)%yu;
ll tt=ksm(x[px])*ksm(y[py])%yu;for(int i=0;i<n;i++){
ll ans=an*tt%yu*x[i]%yu*y[i]%yu;
cout<<ans<<' ';
}cout<<'\n';
}return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 743ms
memory: 11304kb
input:
100 7 12 1 3 2 1 1 4 5 1 4 7 6 5 2 3 4 6 3 1 6 4 7 1 1 2 2 2 2 1 1 2 50 49 49 29 41 33 41 48 27 46 41 36 9 1 41 7 17 12 23 10 8 15 32 6 21 45 18 40 49 21 41 17 41 8 2 35 17 16 38 31 13 5 32 20 36 3 25 18 29 47 29 37 15 23 11 13 29 9 47 44 29 39 41 27 25 28 36 25 19 42 27 38 45 34 15 19 14 24 11 43 1...
output:
2 3 1 4 2 6 2 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 850518977 850518977 850518977 850518977 850518977 850518977 850518977 8...
result:
wrong answer 3rd lines differ - expected: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0', found: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '