Submission #986681

# Submission time Handle Problem Language Result Execution time Memory
986681 2024-05-21T03:05:45 Z chautanphat Race (IOI11_race) C++14
0 / 100
4 ms 7000 KB
#include "race.h"
#include<bits/stdc++.h>
 
using namespace std;
 
const int N = 2e5, W = 1e6;
int n, k, child[N], f[W], ans = N;
bool del[N];
vector<pair<int, int>> a[N];
 
void cntSize(int u, int pre = -1)
{
    child[u] = 1;
    for (int i = 0; i < (int)a[u].size(); i++)
    {
        int v = a[u][i].first;
        if (v == pre || del[v]) continue;
        cntSize(v, u);
        child[u] += child[v];
    }
}
 
int centroid(int u, int sz, int pre = -1)
{
    for (int i = 0; i < (int)a[u].size(); i++)
    {
        int v = a[u][i].first;
        if (v != pre && !del[v] && child[v] > sz/2) return centroid(v, sz, u);
    }
    return u;
}
 
void cal(int u, int dis, int mode, int pre = -1, int h = 1)
{
    if (dis > k) return;
    if (!mode)
        ans = min(ans, h+f[k-dis]);
    else f[dis] = min(f[dis], h);
    for (int i = 0; i < (int)a[u].size(); i++)
    {
        int v = a[u][i].first, w = a[u][i].second;
        if (del[v] || v == pre) continue;
        cal(v, dis+w, mode, u, h+1);
    }
}
 
void reset(int u, int dis, int pre = -1)
{
    if (dis > k) return;
    f[dis] = N;
    for (int i = 0; i < (int)a[u].size(); i++)
    {
        int v = a[u][i].first, w = a[u][i].second;
        if (del[v] || v == pre) continue;
        reset(v, dis+w, u);
    }
}
 
void decompose(int u)
{
    cntSize(u);
    int root = centroid(u, child[u]);
    del[root] = 1;
 
    for (int i = 0; i < (int)a[root].size(); i++)
    {
        int v = a[root][i].first, w = a[root][i].second;
        if (del[v]) continue;
        cal(v, w, 0);
        cal(v, w, 1);
    }
 
    for (int i = 0; i < (int)a[root].size(); i++)
    {
        int v = a[root][i].first, w = a[root][i].second;
        if (del[v]) continue;
        reset(v, w);
    }
 
    for (int i = 0; i < (int)a[root].size(); i++)
        if (!del[a[root][i].first]) decompose(a[root][i].first);
}
 
int best_path(int N1, int K, int H[][2], int L[])
{
  n = N1, k = K;
  for (int i = 1; i <= k; i++) f[i] = N;
  for (int i = 0; i < N1; i++)
  {
    a[H[i][0]].push_back({H[i][1], L[i]});
    a[H[i][1]].push_back({H[i][0], L[i]});
  }
 
  decompose(0);
 
  return (ans == N ? -1 : ans);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 4 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 7000 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Incorrect 3 ms 6748 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 4 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 7000 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Incorrect 3 ms 6748 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 4 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 7000 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Incorrect 3 ms 6748 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 4 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 7000 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Incorrect 3 ms 6748 KB Output isn't correct
12 Halted 0 ms 0 KB -