QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#39922#856. CactusStargazerWA 37ms24160kbC++4.0kb2022-07-14 20:29:092022-07-14 20:29:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-14 20:29:11]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:24160kb
  • [2022-07-14 20:29:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
namespace IO{
#define gc getchar
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
    return f?res:-res;
}
inline ll readll(){
    char ch=gc();
    ll res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
    return f?res:-res;
}
inline char readchar(){
	char ch=gc();
	while(isspace(ch))ch=gc();
	return ch;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	s[top+1]='\0';return top;
}

}
using IO::read;
using IO::readll;
using IO::readchar;
using IO::readstring;
template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}
cs int mod=1e9+7;
inline int add(int a,int b){return (a+b)>=mod?(a+b-mod):(a+b);}
inline int dec(int a,int b){return (a<b)?(a-b+mod):(a-b);}
inline int mul(int a,int b){static ll r;r=(ll)a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){a=(a+b)>=mod?(a+b-mod):(a+b);}
inline void Dec(int &a,int b){a=(a<b)?(a-b+mod):(a-b);}
inline void Mul(int &a,int b){static ll r;r=(ll)a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
inline int fix(ll x){x%=mod;return (x<0)?x+mod:x;}
cs int N=300005,M=400005;
int adj[N],nxt[M<<1],to[M<<1],ecnt;
int n,m;
int K;
int pre[N],bel[N],cnt,up[N];
vector<int> nd[N];
int f[N];
int ff[N],g[N][2];
int vis[N];
void dp(int u,int fa){
 //   cout<<u<<'\n';
    f[u]=1;
    if(!bel[u]){
        for(int e=adj[u],v;e;e=nxt[e])if((e^1)!=fa){
            v=to[e];
            dp(v,e);
            Mul(f[u],mul(f[v],K-1));
        }
    }
    else{
        int tp=bel[u];
        assert(u==up[tp]);
        for(int i=0;i<nd[tp].size();i++){
            int v=nd[tp][i];f[v]=1;
            for(int e=adj[v];e;e=nxt[e])if(bel[to[e]]!=bel[v]&&(e^1)!=fa){
                dp(to[e],e);
                Mul(f[v],mul(f[to[e]],K-1));
            }
            ff[i]=f[v];
        }
        g[0][0]=ff[0];
        g[0][1]=0;
        for(int i=1;i<nd[tp].size();i++){
            g[i][0]=mul(ff[i],g[i-1][1]);
            g[i][1]=mul(ff[i],add(mul(K-1,g[i-1][0]),mul(K-2,g[i-1][1])));
        }
        f[u]=g[nd[tp].size()-1][1];
    }
}
void dfs1(int u,int fa){
    vis[u]=1;
    for(int e=adj[u],v;e;e=nxt[e])if((e^1)!=fa){
        v=to[e];
    //    if(bel[u]&&bel[u]==bel[v])continue;
        if(vis[v]){
            if(bel[v])continue;
            cnt++;
            up[cnt]=v;
            int p=u;
            while(p!=v){
                bel[p]=cnt;
                nd[cnt].pb(p);
                p=pre[p];
            }
            bel[v]=cnt;
            nd[cnt].pb(v);
            reverse(nd[cnt].bg(),nd[cnt].end());
        }
        else{
            pre[v]=u,dfs1(v,e);
        }
    }
}
void solve(){
    ecnt=1;

    n=read(),m=read(),K=read();
    for(int i=1;i<=m;i++){
        int u=read(),v=read();
        nxt[++ecnt]=adj[u],adj[u]=ecnt,to[ecnt]=v;
        nxt[++ecnt]=adj[v],adj[v]=ecnt,to[ecnt]=u;
    }
    dfs1(1,0);
  //  for(int i=1;i<=n;i++)cout<<bel[i]<<" ";puts("");
  //  cout<<"ok1\n";
    dp(1,0);
    cout<<mul(f[1],K)<<'\n';
    memset(adj,0,sizeof(int)*(n+1));
    memset(f,0,sizeof(int)*(n+1));
    memset(vis,0,sizeof(int)*(n+1));
    memset(bel,0,sizeof(int)*(n+1));
    memset(pre,0,sizeof(int)*(n+1));
    memset(up,0,sizeof(int)*(n+1));
    for(int i=1;i<=cnt;i++)nd[i].clear();
    cnt=0;
    return;
}
int main(){
	//freopen("1.in","r",stdin);
    int T=read();
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 24160kb

input:

2
2 1 100
1 2
6 7 3
1 2
2 3
3 1
4 5
5 6
6 4
1 4

output:

9900
24

result:

ok 2 number(s): "9900 24"

Test #2:

score: -100
Wrong Answer
time: 37ms
memory: 22072kb

input:

50000
9 10 4
4 7
5 2
1 5
7 3
9 6
8 3
3 2
9 1
4 8
6 2
10 11 4
4 1
1 3
5 1
10 9
8 4
1 6
7 9
7 10
8 1
1 9
10 2
10 10 4
7 5
6 9
5 1
9 7
10 9
4 9
5 10
2 3
3 7
3 8
9 10 4
3 9
3 7
5 4
6 2
1 9
6 5
4 2
9 8
5 1
7 8
9 9 4
9 4
4 1
6 3
8 7
2 9
6 7
1 8
6 9
5 2
10 11 4
7 8
6 2
9 10
7 2
2 4
4 7
3 7
3 1
10 6
6 9
5 1...

output:

15120
34992
61236
15876
19764
11664
19692
34992
52488
19440
19764
34992
19692
13608
13608
52488
19692
13608
40824
11664
17496
122472
19656
52488
19764
13176
34992
59040
19692
34992
52488
13176
19656
34992
19680
599760
52488
3888
61236
19440
58320
34992
34992
40824
20412
34992
20412
34992
61236
34992...

result:

wrong answer 6th numbers differ - expected: '34992', found: '11664'