QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#203064 | #4648. Average Replacement | yiyiyi# | AC ✓ | 775ms | 49176kb | C++14 | 1016b | 2023-10-06 15:09:22 | 2023-10-06 15:09:22 |
Judging History
answer
#include <bits/stdc++.h>
#include <unordered_map>
#define int long long
#define inf 1e18
#define re register
#define N 1020203
using namespace std;
const int mo=1000000007;
inline int read(){
int x=0,w=0;char ch=getchar();
while (!isdigit(ch))w|=ch=='-',ch=getchar();
while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return w?-x:x;
}
int a[N],vis[N],sum,c[N],tot,col,sum1;
double b[N],d[N];
vector<int>g[N];
void dfs(int u){
if (vis[u])return;
vis[u]=col;
sum+=a[u]*(g[u].size()+1);
sum1+=g[u].size()+1;
for (auto x:g[u])dfs(x);
}
void solve(){
int n=read(),m=read();col=0;
for (int i=1;i<=n;++i)a[i]=read(),g[i].clear(),vis[i]=0;
for (int i=1;i<=m;++i){
int u=read(),v=read();
g[u].push_back(v);
g[v].push_back(u);
}
for (int i=1;i<=n;++i)
if (!vis[i]){
sum=sum1=0;++col;
dfs(i);
b[col]=1.0*sum/sum1;
}
for (int i=1;i<=n;++i)printf("%.6lf\n",b[vis[i]]);
}
signed main(){
int T=read();
while (T--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 775ms
memory: 49176kb
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