QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#534389#4654. Treeship2077WA 1010ms6808kbC++142.9kb2024-08-27 08:49:042024-08-27 08:49:04

Judging History

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

  • [2024-08-27 08:49:04]
  • 评测
  • 测评结果:WA
  • 用时:1010ms
  • 内存:6808kb
  • [2024-08-27 08:49:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=505,mod=1e9+7;
int n,m,x[M],y[M],rec[M][M],tmp[M][M<<1];
int read(){
    int x=0;char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
    return x;
}
int rdc(int x){return x>=mod?x-mod:x;}
int qpow(int x,int n){
    int s=1; while (n){
        if (n&1) s=1ll*s*x%mod;
        x=1ll*x*x%mod; n>>=1;
    } return s;
}
void gauss(int *x){
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
            tmp[i][j+n]=i==j;
    for (int i=1,p=1;i<=n;i++){ int ps=0;
        for (int j=p;j<=n;j++) if (tmp[j][i]) {ps=j;break;}
        if (!ps) continue;
        if (ps!=p) for (int j=i;j<=n<<1;j++)
            swap(tmp[p][j],tmp[ps][j]);
        const int inv=qpow(tmp[p][i],mod-2);
        for (int j=i;j<=n<<1;j++) tmp[p][j]=1ll*tmp[p][j]*inv%mod;
        for (int j=p+1;j<=n;j++) if (tmp[j][i]){
            const int coef=mod-tmp[j][i];
            for (int k=i;k<=n<<1;k++) tmp[j][k]=(tmp[j][k]+1ll*coef*tmp[p][k])%mod;
        }  p++;
    }
    for (int i=1;i<=n;i++){ bool flag=1;
        for (int j=1;j<=n;j++) flag&=!tmp[i][j];
        if (!flag) continue;
        for (int j=1;j<=n;j++) x[j]=tmp[i][j+n];
        return;
    } assert(0);
}
int det(int x,int y){ int ans=1;
    for (int i=1;i<=n;i++) swap(rec[x][i],rec[n][i]);
    for (int i=1;i<=n;i++) swap(rec[i][y],rec[i][n]);
    for (int i=1;i<n;i++){ int p=i;
        for (int j=i;j<n;j++) if (rec[j][i]) {p=j;break;}
        if (p!=i){ ans=mod-ans;
            for (int j=i;j<n;j++) swap(rec[i][j],rec[p][j]);
        }
        if (!rec[i][i]) return 0;
        ans=1ll*ans*rec[i][i]%mod;
        const int inv=qpow(rec[i][i],mod-2);
        for (int j=i;j<n;j++) rec[i][j]=1ll*rec[i][j]*inv%mod;
        for (int j=i+1;j<n;j++) if (rec[j][i]){
            const int coef=mod-rec[j][i];
            for (int k=i;k<n;k++) rec[j][k]=(rec[j][k]+1ll*coef*rec[i][k])%mod;
        }
    }
    return ans;
}
void solve(){
    n=read();m=read();
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
            rec[i][j]=0;
    for (int i=1;i<=m;i++){
        int x=read(),y=read();
        rec[x][y]--;rec[y][y]++;
    }
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
            if (rec[i][j]<0) rec[i][j]+=mod;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++) tmp[i][j]=rec[i][j];
    gauss(x);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++) tmp[j][i]=rec[i][j];
    gauss(y); int posx=0,posy=0;
    for (int i=1;i<=n;i++) if (x[i]) posx=i;
    for (int i=1;i<=n;i++) if (y[i]) posy=i;
    if (!posx||!posy) {for (int i=1;i<=n;i++) printf("0 ");puts("");return;}
    int ans=1ll*det(posx,posy)*qpow(x[posx],mod-2)%mod*qpow(y[posy],mod-2)%mod;
    if (posx+posy&1) ans=mod-ans;
    for (int i=1;i<=n;i++) printf("%lld%c",1ll*ans*x[i]%mod*y[i]%mod," \n"[i==n]);
}
int main(){int T=read();while (T--) solve();return 0;}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1010ms
memory: 6808kb

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 1 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 850518...

result:

wrong answer 12th lines differ - expected: '0 0 0 0 0 0 0 0 0 0 0 0 0 2145...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 0 0 0 0 0 0 0 0 0 0 0 0 7854...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'