Submission #2560392


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 150000;
vector<pair<int, int>> g[N];
vector<double> expect[N];

double dfs(int i, int p, int t) {
  if(expect[i][t] > -1) return expect[i][t];
  expect[i][t] = 0;
  for(auto edge : g[i]) if(edge.first != p) {
    expect[i][t] += (1 + dfs(edge.first, i, edge.second));
  }
  if(g[i].size() - (p != -1)) expect[i][t] /= (g[i].size() - (p != -1));
  return expect[i][t];
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  for(int i = 0; i < n - 1; i++) {
    int a, b; cin >> a >> b; a--; b--;
    expect[a].emplace_back(-1);
    expect[b].emplace_back(-1);
    g[a].emplace_back(b, expect[b].size() - 1);
    g[b].emplace_back(a, expect[a].size() - 1);
  }
  cout << fixed << setprecision(7);
  for(int i = 0; i < n; i++) {
    expect[i].emplace_back(-1);
    cout << dfs(i, -1, expect[i].size() - 1) << endl;
  }
}

Submission Info

Submission Time
Task D - Driving on a Tree
User luma
Language C++14 (GCC 5.4.1)
Score 410
Code Size 962 Byte
Status TLE
Exec Time 1056 ms
Memory 26368 KB

Judge Result

Set Name Subtask1 Subtask2 Subtask3
Score / Max Score 190 / 190 220 / 220 0 / 390
Status
AC × 3
AC × 2
AC × 7
TLE × 1
Set Name Test Cases
Subtask1 sub1_in1.txt, sub1_in2.txt, sub1_in3.txt
Subtask2 sub2_in1.txt, sub2_in2.txt
Subtask3 sub1_in1.txt, sub1_in2.txt, sub1_in3.txt, sub2_in1.txt, sub2_in2.txt, sub3_in1.txt, sub3_in2.txt, sub3_in3.txt
Case Name Status Exec Time Memory
sub1_in1.txt AC 4 ms 7296 KB
sub1_in2.txt AC 7 ms 7424 KB
sub1_in3.txt AC 398 ms 23808 KB
sub2_in1.txt AC 7 ms 7424 KB
sub2_in2.txt AC 7 ms 7424 KB
sub3_in1.txt AC 500 ms 22016 KB
sub3_in2.txt TLE 1056 ms 19168 KB
sub3_in3.txt AC 431 ms 26368 KB