Submission #1004368

# Submission time Handle Problem Language Result Execution time Memory
1004368 2024-06-21T08:20:03 Z Gray Race (IOI11_race) C++17
9 / 100
235 ms 12720 KB
#include<bits/stdc++.h>
#include "race.h"
using namespace std;
#define ll long long
#define ff first
#define ss second
#define ln "\n"
vector<pair<ll, pair<ll, ll>>> e;
vector<vector<ll>> A;
vector<bool> black;
vector<ll> sz;
ll n, k;
void gensz(ll u, ll p){
  sz[u]=1;
  for (auto i:A[u]){
    ll v = e[i].ss.ff^e[i].ss.ss^u;
    if (v==p) continue;
    gensz(v, u);
    sz[u]+=sz[v];
  }
}
void findcentroid(ll u, ll p, ll up, ll &centr, ll wsz){
  bool pos=(up<=wsz/2);
  for (auto i:A[u]){
    if (black[i]) continue;
    ll v = e[i].ss.ff^e[i].ss.ss^u;
    if (v==p) continue;
    if (sz[v]>wsz/2) pos=0;
    findcentroid(v, u, up+1, centr, wsz);
  }
  if (pos) centr=u;
}
void cedfs(ll u, ll &mn, ll wsz, map<ll, ll> &add){
  ll centr = -1;
  findcentroid(u,u, 0, centr, wsz);
  assert(centr!=-1);
  map<ll, ll> lens;
  for (auto i:A[u]){
    if (black[i]) continue;
    black[i]=1;
    ll v = e[i].ss.ff^e[i].ss.ss^u;
    lens.clear();
    cedfs(v, mn, sz[v], lens);
    // cout << v << ": ";
    for (auto [length, tim]:lens){
      // cout << length << "-" << tim << ' ';
      if (add.count(k-length-e[i].ff)){
        mn=min(mn, add[k-length-e[i].ff]+tim+1);
      }
      if (length+e[i].ff==k){
        mn=min(mn, tim+1);
      }
    }
    // cout << ln;
    for (auto [length, tim]:lens){
      if (add.count(length+e[i].ff)){
        add[length+e[i].ff]=min(add[length+e[i].ff], tim+1);
      }else{
        add[length+e[i].ff]=tim+1;
      }
    }
    add[e[i].ff]=1;
  }
}


int best_path(int N, int K, int H[][2], int L[])
{
  n = N; k=K;
  e.resize(N-1);
  A.resize(N);
  for (ll i=0; i<n-1; i++){
    A[H[i][0]].push_back(i);
    A[H[i][1]].push_back(i);
    e[i] = {L[i], {H[i][0], H[i][1]}};
  }
  black.resize(N);
  sz.resize(N);
  ll mn = 2e18;
  gensz(0, 0);
  map<ll, ll> cnt;
  cedfs(0, mn, sz[0], cnt);
  return (mn==2e18?-1:mn);
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 400 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 400 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 1 ms 344 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 400 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 201 ms 10988 KB Output is correct
20 Correct 235 ms 11860 KB Output is correct
21 Correct 163 ms 11352 KB Output is correct
22 Correct 129 ms 12116 KB Output is correct
23 Incorrect 141 ms 12720 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 400 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 1 ms 344 KB Output isn't correct
20 Halted 0 ms 0 KB -