QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#42343#4433. Kitten and RoombaAntistarRE 0ms0kbC++201.1kb2022-08-02 08:11:472022-08-02 08:11:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-02 08:11:47]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-08-02 08:11:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
vector<int> e[N];
int fa[N];
double f[N], g[N];

void dfs(int x, int fa) {
  ::fa[x] = fa;
  for (auto v : e[x]) {
    if (v != fa)
      dfs(v, x);
  }
}

void set_dpv(int x, double val) {
  if (fa[x] != -1)
    g[fa[x]] -= f[x];
  f[x] = val;
  if (fa[x] != -1)
    g[fa[x]] += f[x];
};

double get_val(int u) {
  double res = g[u];
  if (fa[u] != -1)
    res += f[fa[u]];
  return res;
};

void solve() {
  int n, c;
  scanf("%d%d", &n, &c);

  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(1, 0);
  int m;
  scanf("%d", &m);
  vector<int> s;
  for (int i = 1; i <= m; i++) {
    int x;
    scanf("%d", &x);
    s.push_back(x);
  }

  for (int i = m - 1; i >= 0; i--) {
    int x = s[i];
    double w = get_val(x) / (double)e[x].size() + 1;
    set_dpv(x, w);
  }

  printf("%.12lf\n", f[c]);
}

int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
}

详细

Test #1:

score: 0
Runtime Error

input:

2
1000000 315562
969409 917725
324847 719085
524235 603427
576843 433171
75335 238378
266746 487233
80422 95099
594363 96140
858172 261406
958326 466109
233845 350950
863969 345645
689972 81395
395383 27274
93913 208983
523722 380358
108074 172341
130041 692304
737158 383812
752080 33646
154356 6672...

output:


result: