QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642904 | #7040. Connected Subgraphs | FreeTimeLove | AC ✓ | 7909ms | 24576kb | C++14 | 2.1kb | 2024-10-15 16:59:04 | 2024-10-15 16:59:04 |
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
6 5
1 2
2 3
3 4
3 5
3 6
*/
}int main(){re FRTMLV::main();}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9512kb
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: 0
Accepted
time: 790ms
memory: 24576kb
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:
192810800 284251171 771081766 673113026 227774506 23760227 44050220 47307815 414063001 939220437
result:
ok 10 lines
Test #3:
score: 0
Accepted
time: 7909ms
memory: 15176kb
input:
10 693 200000 442 134 485 423 447 184 544 230 46 401 224 156 684 285 227 141 321 647 126 62 644 253 246 509 278 318 104 340 171 116 187 434 554 574 344 285 619 640 240 634 132 193 415 441 130 427 132 134 206 53 102 460 560 312 530 291 479 113 231 455 501 238 666 288 10 422 330 415 240 2 163 302 96 5...
output:
262595832 325062112 160521108 950636215 426755446 561024458 49082359 743032532 582488571 687278985
result:
ok 10 lines
Test #4:
score: 0
Accepted
time: 321ms
memory: 19720kb
input:
10 100000 200000 1 50000 2 50000 3 50000 4 50000 5 50000 6 50000 7 50000 8 50000 9 50000 10 50000 11 50000 12 50000 13 50000 14 50000 15 50000 16 50000 17 50000 18 50000 19 50000 20 50000 21 50000 22 50000 23 50000 24 50000 25 50000 26 50000 27 50000 28 50000 29 50000 30 50000 31 50000 32 50000 33 5...
output:
427268331 405969056 287464978 480992480 583899102 346872966 503167381 491791864 482789441 414972531
result:
ok 10 lines
Test #5:
score: 0
Accepted
time: 333ms
memory: 19492kb
input:
10 100000 200000 50000 50001 1 50001 2 50001 3 50001 4 50001 5 50001 6 50001 7 50001 8 50001 9 50001 10 50001 11 50001 12 50001 13 50001 14 50001 15 50001 16 50001 17 50001 18 50001 19 50001 20 50001 21 50001 22 50001 23 50001 24 50001 25 50001 26 50001 27 50001 28 50001 29 50001 30 50001 31 50001 3...
output:
318946949 387994406 758360868 579574960 687516111 966394852 864355459 29275977 871937345 134220714
result:
ok 10 lines