Submission #770021

# Submission time Handle Problem Language Result Execution time Memory
770021 2023-06-30T16:50:39 Z vjudge1 Paths (RMI21_paths) C++17
12 / 100
97 ms 19164 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "C:\GCC\debug.h"
#else
#define debug(...) void(42)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, k;
  cin >> n >> k;

  vector<vector<array<long long, 2>>> adj(n);

  for (int i = 0; i < n - 1; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    --u, --v;
    adj[u].push_back({v, c});
    adj[v].push_back({u, c});
  }

  vector<vector<long long>> d(n, vector<long long> (2));
  vector<long long> res(n);

  function<void(int, int)> Dfs = [&](int u, int prev) {
    for (auto v : adj[u]) {
      if (v[0] == prev) {
        continue;
      }
      Dfs(v[0], u);
      if (d[v[0]][0] + v[1] > d[u][0]) {
        d[u][1] = d[u][0];
        d[u][0] = d[v[0]][0] + v[1];
      } else if (d[v[0]][0] + v[1] > d[u][1]) {
        d[u][1] = d[v[0]][0] + v[1];
      }
    }
  };

  Dfs(0, -1);

  function<void(int, int, long long)> Dfs2 = [&](int u, int prev, long long c) {
    res[u] = max(c, d[u][0]);

    for (auto v : adj[u]) {
      if (v[0] == prev) {
        continue;
      }
      if (d[v[0]][0] + v[1] == d[u][0]) {
        Dfs2(v[0], u, max(c, d[u][1]) + v[1]);
      } else {
        Dfs2(v[0], u, res[u] + v[1]);
      }
    }
  };

  Dfs2(0, -1, 0);

  for (int root = 0; root < n; root++) {
    cout << res[root] << '\n';  
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 15436 KB Output is correct
2 Correct 97 ms 19164 KB Output is correct
3 Correct 59 ms 16224 KB Output is correct
4 Correct 82 ms 16368 KB Output is correct
5 Correct 67 ms 17480 KB Output is correct
6 Correct 64 ms 16156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -