Submission #891289

# Submission time Handle Problem Language Result Execution time Memory
891289 2023-12-22T16:38:24 Z Erfan1386Y Race (IOI11_race) C++14
0 / 100
4 ms 18012 KB
#include "race.h"
#include <bits/stdc++.h>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << '\n';
#define kill(x) {cout << x << '\n'; return 0;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 1e16, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621;

using namespace std;

#define int ll

const ll N = 2e5 + 10, LG = 20;
ll n, k, ans = inf;
vector<pii> adj[N];
set<pii> s[N];

void add (int v, int u, int w) {
  for (auto x: s[u]) {
    auto y = *s[v].lower_bound(pii(k - x.F - w, 0));
    if (y.F != k - x.F - w) continue;
    ans = min(ans, x.S + y.S + 1);
  }
  for (auto x: s[u]) {
    s[v].insert({x.F + w, x.S + 1});
  }
  s[u].clear();
}

void dfs (int v, int p = -1) {
  for (auto u: adj[v]) {
    if (u.F - p) {
      dfs(u.F, v);
      if (s[v].size() < s[u.F].size())
        s[v].swap(s[u.F]);
      add(v, u.F, u.S);
    }
  }
}

int32_t best_path(int32_t N, int32_t K, int32_t H[][2], int32_t L[]) {
  fast_io;
  n = N, k = K;
  for (int i = 0; i <= n; i++) {
    s[i].insert({inf, 0});
    s[i].insert({0, 0});
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    u = H[i][0], v = H[i][1];
    w = L[i];
    adj[u].pb({v, w});
    adj[v].pb({u, w});
  }
  dfs(0);
  // for (auto u: s[0])
    // cout << u.F << ' ' << u.S << '\n';
  if (ans >= inf)
    return -1;
  return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 18012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 18012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 18012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 18012 KB Output isn't correct
2 Halted 0 ms 0 KB -