QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#100330#4648. Average Replacementjcccc#AC ✓1916ms11240kbC++171.4kb2023-04-25 16:56:192023-04-25 16:56:19

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-25 16:56:19]
  • 评测
  • 测评结果:AC
  • 用时:1916ms
  • 内存:11240kb
  • [2023-04-25 16:56:19]
  • 提交

answer

//B站关注 艾尔莎 喵
//All OK
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ios ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(0);cout << fixed << setprecision(6)
#define INF 1ll*1e10
#define LNF (1ll << 60)
#define PII pair<int, int>
#define PI acos(-1)
#define ll long long
// #define ll __int128 
#define int ll
#define endl '\n'
using namespace std;

const int N = 3e5 + 10;
int n, m;
ll sum[N];
ll sz[N], d[N], a[N];
int f[N];

int find(int x){
    return x == f[x] ? x : f[x] = find(f[x]);
}

void solve(){
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
        f[i] = i, sum[i] = sz[i] = 0, d[i] = 1;
    for(int i = 1; i <= n; i ++)
        cin >> a[i];

    for(int i = 1; i <= m; i ++){
        int u, v;
        cin >> u >> v;
        d[u] ++, d[v] ++;
        int fx = find(u), fy = find(v);
        // cout << fx << ' ' << fy << endl;
        if(fx != fy) f[fy] = fx;
    }

    for(int i = 1; i <= n; i ++){
        int x = find(i);
        sum[x] += a[i] * d[i];
        sz[x] += d[i];
    }

    for(int i = 1; i <= n; i ++){
        int x = find(i);
        cout << 1.0 * sum[x] / sz[x] << endl;
    }
}   

signed main(){
    ios;

    // init();
    int _ = 1;
    cin >> _;
    for(int __ = 1; __ <= _; __ ++){
        // cout << "Case " << __ << ": ";
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1916ms
memory: 11240kb

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