square869120Contest #4

Submission #1321743

Source codeソースコード

#include <iostream>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;

int n;
vector<vector<int>> edges(150000 + 10);

void read() {
    cin >> n;
    for(int i = 1; i <= n - 1; i++) {

        int x, y;
        cin >> x >> y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
}

int par[150000 + 10], co[150000 + 10];
double expected[150000 + 10], result[150000 + 10];

double dfs(int node, int parent) {
    par[node] = parent;
    for(int son : edges[node]) {
        if(son != parent)
        dfs(son, node);
    }
    for(int son : edges[node]) {
        if(son != parent) {
                co[node]++;
        }
    }
    if(co[node])
    for(int son : edges[node]) {
        if(son != parent)
        expected[node] += (1 + expected[son]) / (double)co[node];
    }
}


void dfs1(int node, int parent) {
    if(node == 1) {
        result[1] = expected[1];
    }
    else{
    result[node] = ((double) co[node]/ ((double) (co[node] + 1))) * expected[node];
    if(par[node] != 1) {
        double res = (double) result[par[node]] * (co[par[node]] + 1) - expected[node] - 1;
        res = res / (double)(co[par[node]]);
        res++;
        result[node] += 1/((double)(co[node] + 1)) * res;
    } else {
        if(par[node] == 1 && co[1] >= 2) {
            double res = (double) result[par[node]] * (co[par[node]]) - expected[node] - 1;
            res = res / (double)(co[par[node]] - 1);
            res++;
            result[node] += 1/((double)(co[node] + 1)) * res;
        } else {
            result[node] += 1/(double)(1 + co[node]);
        }
    }
    }
    for(int i : edges[node]) {
        if(i != parent) {
            dfs1(i, node);
        }
    }
}

void solve() {
    dfs1(1, 0);
    for(int i = 1; i <= n; i++) {
        cout << setprecision(15) << result[i] << endl;
    }

}

int main()
{
    read();
    dfs(1, 0);
    solve();
    return 0;
}

Submission

Task問題 A - Atcoder Handles
User nameユーザ名 Viorel123
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 2007 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Subtask1 0 / 130 sub1_in1.txt,sub1_in2.txt,sub1_in3.txt
Subtask2 0 / 120 sub1_in1.txt,sub1_in2.txt,sub1_in3.txt,sub2_in1.txt,sub2_in2.txt,sub2_in3.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sub1_in1.txt WA
sub1_in2.txt WA
sub1_in3.txt WA
sub2_in1.txt WA
sub2_in2.txt WA
sub2_in3.txt WA