QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620394 | #2439. Line Graphs | Afterlife# | AC ✓ | 602ms | 40440kb | C++20 | 4.6kb | 2024-10-07 17:55:51 | 2024-10-07 17:55:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=1000020;
int n,m,d[N];
vector<int> G[N],cg[N];
ll ans,tot;
struct Ans{
int mx;
ll tot;
};
Ans Merge(Ans a,Ans b){
if(a.mx>b.mx)return a;
if(b.mx>a.mx)return b;
a.tot=(a.tot+b.tot)%mod;
return a;
}
inline int C2(int x){
return 1LL*x*(x-1)/2%mod;
}
inline int C3(int x){
return 1LL*x*(x-1)*(x-2)/6%mod;
}
int k;
vector<pair<int,int> > H[N];
vector<pair<int,int> > E;
void Baoli(){
for(int t=1;t<=k;++t){
int z=E.size();
for(int i=1;i<=n;++i){
H[i].clear();
}
for(int i=0;i<(int)E.size();++i){
int u=E[i].first,v=E[i].second;
H[u].emplace_back(v,i+1);
H[v].emplace_back(u,i+1);
}
vector<pair<int,int> > _E;
for(int u=1;u<=n;++u){
for(int i=0;i<(int)H[u].size();++i){
for(int j=i+1;j<(int)H[u].size();++j){
_E.emplace_back(H[u][i].second,H[u][j].second);
}
}
}
n=z;
E=_E;
}
for(int i=1;i<=n;++i)G[i].clear();
for(auto [u,v]:E){
G[u].push_back(v);
G[v].push_back(u);
}
Ans ans={0,1};
if(n)
ans=Merge(ans,{1,n});
if(E.size())
ans=Merge(ans,{2,(int)E.size()});
Ans now={3,0};
vector<int> vis(n+1);
for(int u=1;u<=n;++u){
for(auto x:G[u])
vis[x]++;
for(auto x:G[u]){
for(auto y:G[x]){
if(y==u)
continue;
now.tot=(now.tot+vis[y])%mod;
}
}
for(auto x:G[u])
vis[x]--;
}
now.tot/=6;
if(now.tot)
ans=Merge(ans,now);
cout<<ans.mx<<' '<<ans.tot<<'\n';
}
void Solve(){
cin>>n>>m>>k;
E.clear();
for(int i=1;i<=n;++i){
cg[i].clear();
G[i].clear();
}
for(int i=1;i<=m;++i){
int u,v;
cin>>u>>v;
G[u].push_back(v);
G[v].push_back(u);
E.emplace_back(u,v);
}
for(int i=1;i<=n;++i){
d[i]=G[i].size();
}
for(int i=1;i<=n;++i){
sort(G[i].begin(),G[i].end(),[&](int u,int v){return G[u].size()>G[v].size();});
cg[i].resize(G[i].size());
for(int j=(int)cg[i].size()-1;j>=0;--j){
cg[i][j]=1;
if(j+1<(int)cg[i].size()&&d[G[i][j]]==d[G[i][j+1]])cg[i][j]+=cg[i][j+1];
}
}
Ans ans={0,0};
if(k==1){
for(int i=1;i<=n;++i){
ans=Merge(ans,{d[i],1});
}
}
else if(k==2){
for(auto [u,v]:E){
ans=Merge(ans,{d[u]+d[v]-2,1});
}
}
else if(k==3){
for(int u=1;u<=n;++u){
if(d[u]<2)continue;
Ans now;
now.mx=2*d[u]+d[G[u][0]]+d[G[u][1]]-6;
if(d[G[u][0]]==d[G[u][1]]){
now.tot=C2(cg[u][0]);
}
else{
now.tot=cg[u][1];
}
ans=Merge(ans,now);
}
}
else{
for(auto [u,v]:E){
if(d[u]<2||d[v]<2)continue;
Ans now;
int x=G[u][0]==v?G[u][1]:G[u][0];
int y=G[v][0]==u?G[v][1]:G[v][0];
now.mx=3*(d[u]+d[v])+(d[x]+d[y])-14;
int cx=(G[u][0]==v?cg[u][1]:(cg[u][0]-(d[x]==d[v])));
int cy=(G[v][0]==u?cg[v][1]:(cg[v][0]-(d[y]==d[u])));
now.tot=1ll*cx*cy%mod;
// now.tot=1LL*cg[u][G[u][0]==v]*cg[v][G[v][0]==u]%mod;
ans=Merge(ans,now);
}
for(int u=1;u<=n;++u){
if(d[u]<3)continue;
Ans now;
int d2=d[G[u][0]];
int d3=d[G[u][1]];
int d4=d[G[u][2]];
now.mx=4*d[u]+2*d[G[u][0]]+d[G[u][1]]+d[G[u][2]]-14;
if(d2==d3){
if(d3==d4){
now.tot=1LL*C2(cg[u][0]-1)*cg[u][0]%mod;
}
else{
now.tot=2*cg[u][2];
}
}
else{
if(d3==d4){
now.tot=C2(cg[u][1]);
}
else{
now.tot=cg[u][2];
}
}
ans=Merge(ans,now);
}
}
if(ans.mx<=3){
Baoli();
return;
}
cout<<ans.mx<<' '<<ans.tot<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin>>T;
while(T--)
Solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7760kb
input:
3 5 0 4 5 4 1 1 2 1 3 1 4 1 5 5 4 4 1 2 1 3 1 4 1 5
output:
0 1 4 1 6 12
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 7684kb
input:
12 8 7 1 1 2 1 3 1 4 1 5 6 7 7 8 8 6 8 7 2 1 2 1 3 1 4 1 5 6 7 7 8 8 6 8 7 3 1 2 1 3 1 4 1 5 6 7 7 8 8 6 8 7 4 1 2 1 3 1 4 1 5 6 7 7 8 8 6 8 7 1 1 2 1 3 1 4 4 5 6 7 7 8 8 6 8 7 2 1 2 1 3 1 4 4 5 6 7 7 8 8 6 8 7 3 1 2 1 3 1 4 4 5 6 7 7 8 8 6 8 7 4 1 2 1 3 1 4 4 5 6 7 7 8 8 6 10 8 1 1 2 1 3 1 4 4 5 6 ...
output:
4 1 3 9 4 6 6 12 3 2 3 3 3 5 4 1 4 1 3 10 4 6 6 12
result:
ok 12 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 7700kb
input:
100 13 29 3 6 8 5 11 8 13 3 9 1 8 6 12 4 11 2 12 3 11 6 10 8 11 3 13 4 8 6 13 3 12 8 9 9 10 6 9 7 12 8 12 1 3 1 2 2 13 4 6 1 4 10 13 2 4 6 11 2 10 12 1 4 7 8 20 34 3 8 17 3 20 2 14 14 17 8 12 9 18 3 15 16 19 1 17 9 13 8 18 2 9 17 20 7 16 13 16 10 12 7 11 11 15 7 10 3 7 7 8 1 10 4 20 13 15 4 14 13 14...
output:
20 8 0 1 16 1 3 4 1 1 32 6 8 1 8 1 7 1 3 2 6 1 6 2 0 1 11 3 0 1 7 2 20 3 7 2 0 1 50 1 11 1 26 3 7 1 0 1 2 2 30 95 36 3 18 4 64 1 17 1 5 2 24 1 3 1 0 1 10 2 0 1 25 2 5 1 1 1 8 1 2 3 0 1 7 2 11 2 4 1 6 5 34 3 11 2 22 3 3 1 22 1 35 1 25 2 42 150 3 8 4 7 5 6 72 4 0 1 5 2 1 1 2 1 3 1 8 19 6 1 34 12 54 3 ...
result:
ok 100 lines
Test #4:
score: 0
Accepted
time: 602ms
memory: 40440kb
input:
1000 5 0 4 5 4 1 1 2 1 3 1 4 1 5 5 4 4 1 2 1 3 1 4 1 5 3 0 3 7 20 3 7 5 7 2 1 6 2 3 5 1 7 4 5 6 1 2 2 6 6 4 4 3 4 2 3 5 7 3 4 1 1 7 3 6 3 1 7 6 4 5 6 5 2 3 1 5 1 2 6 6 1 6 3 9 7 3 1 6 6 4 8 3 3 7 2 8 7 6 7 5 6 5 3 3 2 3 1 2 1 6 5 6 3 4 4 2 1 2 2 4 2 3 3 4 4 5 1 3 2 2 4 1 2 3 4 1 3 7 2 3 4 6 7 3 10 2...
output:
0 1 4 1 6 12 0 1 18 30 4 1 5 1 4 3 3 4 3 4 0 1 16 1 0 1 19 3 0 1 0 1 0 1 2 2 22 3 40 6 6 7 0 1 0 1 4 1 5 3 0 1 0 1 18 3 3 1 0 1 9 8 0 1 15 4 28 6 1 1 1 1 0 1 0 1 0 1 6 3 3 1 1 1 25 6 34 36 8 3 10 4 10 3 40 1 0 1 0 1 1 1 0 1 4 1 8 2 6 2 1 1 2 1 1 1 26 12 0 1 0 1 3 1 2 1 6 1 11 1 18 30 14 13 0 1 1 1 0...
result:
ok 1000 lines