QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#623031 | #4648. Average Replacement | vision | AC ✓ | 1204ms | 27376kb | C++20 | 1.1kb | 2024-10-09 09:41:53 | 2024-10-09 09:41:53 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define lson k<<1
#define rson (k<<1)|1
#define debug cout<<666<<endl;
using namespace std;
const int N=1e6+5;
vector<int>v[N];
int f[N];
int find(int x){
if(f[x]!=x)f[x]=find(f[x]);
return f[x];
}
int si[N];
int sum[N];
int a[N];
void vision()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
f[i]=i;
cin>>a[i];
sum[i]=si[i]=0;
v[i].clear();
}
for(int j=1;j<=m;j++){
int x,y;
cin>>x>>y;
v[x].push_back(y);v[y].push_back(x);
int tx=find(x),ty=find(y);
f[tx]=ty;
}
for(int i=1;i<=n;i++){
int tx=find(i);
sum[tx]+=(a[i]*((int)v[i].size()+1));
si[tx]+=((int)v[i].size()+1);
}
for(int i=1;i<=n;i++){
int tx=find(i);
double ans=(double)sum[tx]/si[tx];
cout<<fixed<<setprecision(6)<<ans<<"\n";
}
return ;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
cin>>t;
while(t--){
vision();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1204ms
memory: 27376kb
input:
100 2 1 1 2 1 2 4 2 1 2 3 4 1 2 3 4 1000 10 12861608 81251431 94636305 97860396 13361461 89521381 9573845 5613423 65053967 22867045 63074541 7376557 68562801 21216095 78889305 34739974 74647393 32495323 15113554 1391235 57948633 91911807 89671183 70279905 48099886 30931849 2289485 44602370 36977326 ...
output:
1.500000 1.500000 1.500000 1.500000 3.500000 3.500000 12861608.000000 81251431.000000 94636305.000000 97860396.000000 13361461.000000 89521381.000000 9573845.000000 5613423.000000 65053967.000000 22867045.000000 63074541.000000 7376557.000000 68562801.000000 21216095.000000 78889305.000000 34739974....
result:
ok 2079006 lines