Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
34826 武云帆 【S】T2 C++ 内存超限 20 177 MS 295324 KB 2681 2024-11-14 19:18:50

Tests(2/10):


#include<bits/stdc++.h> using namespace std; #define int long long int n,q,idx; const int N=3010; int f[N],siz[N]; struct node{ int x,y; }a[N]; int find(int x){ if(f[x]!=x) f[x]=find(f[x]); return f[x]; } priority_queue<pair<int,pair<int,int> >,vector<pair<int,pair<int,int> > >,greater<pair<int,pair<int,int> > > > q1,q2; signed main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>n>>q; for(int i=1;i<=n;i++){ siz[i]=1; f[i]=i; cin>>a[i].x>>a[i].y; for(int j=1;j<i;j++){ q1.push({abs(a[i].x-a[j].x)*abs(a[i].x-a[j].x)*abs(a[i].x-a[j].x)+abs(a[i].y-a[j].y)*abs(a[i].y-a[j].y)*abs(a[i].y-a[j].y),{i,j}}); } } int k=1; long long ans=0; while(!q1.empty()&&k<n){ int x=find(q1.top().second.first); int y=find(q1.top().second.second); if(x!=y){ if(siz[x]<siz[y]) swap(x,y); siz[y]+=siz[x]; f[x]=f[y]; ans+=q1.top().first; q2.push({q1.top().first,{q1.top().second.first,q1.top().second.second}}); k++; } q1.pop(); } printf("%lld\n",ans); if(q==0){ return 0; } while(!q1.empty()) q1.pop(); for(int i=1;i<=q;i++){ int x,y,z; cin>>x>>y>>z; memset(siz,1,sizeof siz); for(int i=1;i<=n;i++) f[i]=i; if(i%2==1){ q2.push({z,{x,y}}); k=1;ans=0; while(!q2.empty()&&k<n){ int x=find(q2.top().second.first); int y=find(q2.top().second.second); if(x!=y){ if(siz[x]<siz[y]) swap(x,y); siz[y]+=siz[x]; f[x]=y; ans+=q2.top().first; q1.push({q2.top().first,{q2.top().second.first,q2.top().second.second}}); k++; } q2.pop(); } printf("%lld\n",ans); } else{ q1.push({z,{x,y}}); k=1;ans=0; while(!q1.empty()&&k<n){ int x=find(q1.top().second.first); int y=find(q1.top().second.second); if(x!=y){ if(siz[x]<siz[y]) swap(x,y); siz[y]+=siz[x]; f[x]=y; ans+=q1.top().first; q2.push({q1.top().first,{q1.top().second.first,q1.top().second.second}}); k++; } q1.pop(); } printf("%lld\n",ans); } } }


测评信息: