QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#642871 | #7040. Connected Subgraphs | FreeTimeLove | WA | 790ms | 24708kb | C++14 | 2.2kb | 2024-10-15 16:43:19 | 2024-10-15 16:43:19 |
Judging History
answer
/*FreeTimeLove's code.
Love has a nasty habit of disappearing over night.*/
#include<bits/stdc++.h>
namespace FRTMLV{
#define ll long long
#define LD long double
#define i7 __int128
#define re return
#define con continue
using namespace std;
template<class T>inline bool ckmin(T &a,T b){re b<a?a=b,1:0;}
template<class T>inline bool ckmax(T &a,T b){re a<b?a=b,1:0;}
const int N=1e5+5;
inline int rd(){
int ans=0,f=0;
char ch=getchar();
while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
while(ch>='0'&&ch<='9')ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
re f?-ans:ans;
}
const int mod=1e9+7;
int n,m,id[N],dgr[N],bk[N],rk[N];
vector<int>e[N],E[N];
int cnt[N];
int main(){
int T=rd();
while(T--){
n=rd(),m=rd();
memset(dgr,0,sizeof dgr);
memset(bk,0,sizeof bk);
for(int i=1;i<=n;i++)id[i]=i,e[i].clear(),E[i].clear();
for(int i=1;i<=m;i++){
int u=rd(),v=rd();
e[u].push_back(v),e[v].push_back(u);
++dgr[u],++dgr[v];
}
sort(id+1,id+n+1,[](int x,int y){re dgr[x]>dgr[y];});
for(int i=1;i<=n;i++)rk[id[i]]=i;
for(int i=1;i<=n;i++)
for(auto u:e[i])
if(rk[i]<rk[u])E[i].push_back(u);
ll ans=0;
for(int i=1;i<=n;i++){
ans+=(i7)dgr[i]*(dgr[i]-1)*(dgr[i]-2)*(dgr[i-3])/24%mod;//juhua
if(dgr[i]==1)con;
ll sum=0,D=(ll)(dgr[i]-1)*(dgr[i]-2)/2;
for(auto v:e[i]){
ans+=sum*(dgr[v]-1)%mod;//chain
ans+=D*(dgr[v]-1)%mod;//2-
sum+=dgr[v]-1;
}
}
for(int I=1;I<=n;I++){
int i=id[I];
for(auto u:E[i])bk[u]=i;//
for(auto u:E[i]){
for(auto v:e[u]){
if(rk[v]>rk[u]&&bk[v]==i){
ans+=(ll)(dgr[u]+dgr[v]+dgr[i]-6)*(mod+1-4)%mod;//3-ring-1
// printf("[%d] ",dgr[u]+dgr[v]+dgr[i]-6);
ans+=mod-3;//3-ring
// ans+=cnt*(mod+1-4)%mod;//4-ring
}
if(rk[v]>rk[i]){
ans+=(ll)(cnt[v]++)*(mod+1-4)%mod;//4-ring
// printf("{%d} ",cnt[v]-1);
}
}
}
for(auto u:E[i]){
if(rk[u]<rk[i])con;
for(auto v:e[u])cnt[v]=0;
}
}
printf("%lld\n",ans%mod);
}
re 0;
}
/*
1
4 6
1 2
1 3
1 4
2 3
2 4
3 4
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
*/
}int main(){re FRTMLV::main();}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9944kb
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: 790ms
memory: 24708kb
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:
151203374 276020268 772914369 670965674 225042648 23750776 44042025 47309720 993248876 1549070
result:
wrong answer 1st lines differ - expected: '192810800', found: '151203374'