QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#645189#9474. Colored NodesAfterlife#WA 268ms19520kbC++201.9kb2024-10-16 17:12:572024-10-16 17:13:00

Judging History

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

  • [2024-10-16 17:13:00]
  • 评测
  • 测评结果:WA
  • 用时:268ms
  • 内存:19520kb
  • [2024-10-16 17:12:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int n , m;
vector<int> E[100005];
vector<int> to[100005];
int col[100005];
void dfs(int u,int c) {
    col[u] = c;
    for(auto v : to[u]) dfs(v , c);
}
typedef long long ll;
int main() {
    ios::sync_with_stdio(false) ; cin.tie(0) ;
    while(cin >> n >> m) {
        for(int i = 1;i <= n;i++) E[i].clear() , to[i].clear() , col[i] = 0;
        for(int i = 1;i <= m;i++) {
            int u , v;cin >> u >> v;
            E[u].push_back(v) ;
            E[v].push_back(u);
        }
        vector<int> in(n + 1);
        for(int i = 1;i <= n;i++) {
            sort(E[i].begin() , E[i].end()) ;
            if(!E[i].size()) continue ;
            if(E[i][0] < i) {
                in[i] = 1;
                auto it = lower_bound(E[i].begin() , E[i].end() , i) ;
                it-- ;
                to[*it].push_back(i);
            }
        }
        for(int i = 1;i <= n;i++) {
            if(!in[i]) dfs(i , i);
        }
        vector<ll> a(n + 1) , b(n + 1) , t(n + 1);
        for(int i = 1;i <= n;i++) {
            t[i] = 1 , a[col[i]]++ ;
            // printf("%d %d\n",i,col[i]);
        }
        auto upd = [&](int u,int v,int i)-> void {
            b[u] += 1LL * a[u] * (i - t[u]) ;
            t[u] = i;
            a[u] += v;
        };
        for(int i = 1;i <= n;i++) {
            for(auto v : E[i]) {
                upd(col[v] , -1 , i);
                upd(col[i] , 1 , i);
                col[v] = col[i];
            }
        }
        for(int i = 1;i <= n;i++) b[i] += 1LL * a[i] * (n + 1 - t[i]);
        sort(b.begin() + 1 , b.end()) ;
        for(int i = n;i >= 1;i--) {
            if(b[i] == 0) break ;
            // cout << b[i] << '\n';
            cout << fixed << setprecision(6) << (double)b[i] / n << '\n';
        }
        // break ;
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3996kb

input:

5 5
1 2
2 5
3 4
4 5
3 5
5 4
1 2
2 5
5 4
4 3

output:

3.000000
2.000000
2.800000
2.200000

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 268ms
memory: 19520kb

input:

10 10
1 2
2 3
3 4
4 5
5 6
10 7
7 8
8 9
9 10
6 9
10 10
6 5
5 3
3 4
4 2
6 1
10 7
7 8
8 9
9 10
6 10
4 3
1 2
2 3
3 4
8 12
4 7
7 6
7 2
7 3
2 5
5 7
4 3
7 2
7 6
3 4
4 5
4 8
100 100
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25...

output:

6.000000
4.000000
4.700000
4.000000
0.900000
0.400000
4.000000
3.750000
2.375000
1.000000
0.875000
52.040000
3.310000
2.990000
2.990000
2.990000
2.990000
2.990000
2.990000
2.990000
2.990000
2.990000
2.990000
2.990000
2.990000
2.990000
2.950000
2.830000
11.940000
11.370000
5.290000
3.590000
3.310000
...

result:

wrong answer 1st lines differ - expected: '5.600000', found: '6.000000'