QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#604273#7040. Connected SubgraphstarjenWA 1060ms23096kbC++202.7kb2024-10-02 04:30:382024-10-02 04:30:38

Judging History

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

  • [2024-10-02 04:30:38]
  • 评测
  • 测评结果:WA
  • 用时:1060ms
  • 内存:23096kb
  • [2024-10-02 04:30:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
void add(int &x,int y){
    if((x+=y)>=mod)x-=mod;
}
void del(int &x,int y){
    if((x-=y)<0)x+=mod;
}
const int Ny24=41666667;
ll C4(int n){
    if(n<=3)return 0;
    return (ll)n*(n-1)%mod*(n-2)%mod*(n-3)%mod*Ny24%mod;
}
const bool test=false;
ll solve(){
    int n,m;cin>>n>>m;
    vector<pair<int,int>> edges(m);
    vector<int>d(n+1),flg(n+1),id(n+1),rk(n+1),c(n+1);
    vector<vector<int>> ve(n+1),f(n+1),g(n+1);
    int ans=0,ans3=0,ans4=0,circle3=0;
    // ans 链 3 三元环 4四元环
    for(int i=0;i<m;i++){
        int u,v;cin>>u>>v;
        edges[i]=make_pair(u,v);
        ve[u].push_back(v);
        ve[v].push_back(u);
    }
    for(int i=1;i<=n;i++)
        d[id[i]=i]=(int)ve[i].size();
    {//菊花
        for(int i=1;i<=n;i++)add(ans,C4(d[i]));
        if(test)cout<<"flower = "<<ans<<endl;
    }
    for(auto [u,v]:edges){
        if(d[u]>d[v]||(d[u]==d[v]&&u>v))g[u].push_back(v);
        else g[v].push_back(u);
    }
    sort(id.begin()+1,id.end(),[&](int x,int y){
        return d[x]<d[y];
    });
    for(int i=1;i<=n;i++)rk[id[i]]=i;
    for(int u=1;u<=n;u++)for(auto v:ve[u])
        if(rk[v]>rk[u])f[u].push_back(v);
    for(int u=1,C=0;u<=n;u++){
        for(auto v:ve[u])for(auto w:f[v])if(rk[w]>rk[u])add(ans4,c[w]),++c[w];
        for(auto v:ve[u])for(auto w:f[v])if(rk[w]>rk[u])c[w]=0;
        ++C;
        for(auto v:g[u])flg[v]=C;
        for(auto v:g[u])
            for(auto w:g[v])if(flg[w]==C){
                add(ans3,d[u]-2+d[v]-2+d[w]-2);
                add(circle3,1);
            }
    }
    if(test)cout<<"ans3 = "<<ans3<<endl;
    if(test)cout<<"ans4 = "<<ans4<<endl;

    {//分叉
        int res=0;
        for(auto [x,y]:edges){
            if(d[x]>=2&&d[y]>=3)add(res,(ll)(d[x]-1)*(d[y]-2)%mod);
            if(d[y]>=2&&d[x]>=3)add(res,(ll)(d[y]-1)*(d[x]-2)%mod);
        }
        del(res,2ll*ans3%mod);
        add(ans,res);
        if(test)cout<<"one-two = "<<res<<endl;
    }
    {//链
        int res=0;
        for(int i=1;i<=n;i++)if(d[i]>=2){
            int all=0;
            for(auto it:ve[i])if(d[it]>=2){
                del(res,((ll)(d[it]-1)*(d[it]-2)/2)%mod);
                add(all,d[it]-1);
            }
            add(res,((ll)all*(all-1)/2)%mod);

        }
        del(res,2ll*ans3%mod);
        del(res,4ll*ans4%mod);
        del(res,3ll*circle3%mod);
        add(ans,res);
        if(test)cout<<"chain = "<<res<<endl;
    }
    add(ans,ans3);
    add(ans,ans4);
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;while(T--)cout<<solve()<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

2
4 4
1 2
2 3
3 4
4 1
4 6
1 2
1 3
1 4
2 3
2 4
3 4

output:

1
15

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 1060ms
memory: 23096kb

input:

10
3296 174079
484 736
80 3275
914 1609
611 2069
1111 3027
749 1443
568 1878
1180 2788
1072 2156
171 797
106 1226
1749 2331
758 3080
772 2017
1381 2393
1945 2943
269 1431
1640 1805
1924 2161
1720 2123
1551 2940
286 1226
460 1462
1807 1823
40 638
18 707
589 849
1857 1987
914 2360
2446 3129
24 910
113...

output:

876732514
130126748
339585568
315289780
339029313
16499761
29577137
31961046
776739435
128254243

result:

wrong answer 1st lines differ - expected: '192810800', found: '876732514'