답안 #541607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541607 2022-03-23T20:34:55 Z Evang 경주 (Race) (IOI11_race) C++17
100 / 100
497 ms 34372 KB
#include <bits/extc++.h>
#include "race.h"
using namespace std;
using namespace __gnu_pbds;
 
#ifdef _DEBUG
#define dout(x) clog << "Line " << __LINE__ << ": " << #x << "=" << (x) << el
#else
#define dout(x)
#endif
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define uid(a,b) uniform_int_distribution<int>(a,b)(rng)
 
#define ins insert
#define ssize(x) (int((x).size()))
#define bs(args...) binary_search(args)
#define lb(args...) lower_bound(args)
#define ub(args...) upper_bound(args)
#define all(x) (x).begin(),(x).end()
#define mp(a, b) make_pair(a, b)
#define mt(args...) make_tuple(args)
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define die exit(0)
 
template<typename T>
using vc = vector<T>;
template<typename T>
using uset = unordered_set<T>;
template<typename A, typename B>
using umap = unordered_map<A, B>;
template<typename T, typename Comp>
using pq = std::priority_queue<T, vc<T>, Comp>;
template<typename T>
using maxpq = pq<T, less<T>>;
template<typename T>
using minpq = pq<T, greater<T>>;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using db = double;
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vc<int>;
using vll = vc<ll>;
using vpi = vc<pi>;
using vpll = vc<pll>;
using str = string;
 
constexpr char el = '\n';
constexpr char sp = ' ';
constexpr int inf = 0x3f3f3f3f;
constexpr ll llinf = 0x3f3f3f3f3f3f3f3fLL;
// ---------------------------------------------------------------------
 
 
const int N = 2e5+5;
const int K = 1e6+5;
int n, k, ans = inf, sub[N];
vpi adj[N];
bitset<N> r;
 
struct evan {
    int a[K];
    vi un;
    evan() {
        memset(a, 0x3f, sizeof a);
        a[0] = 0;
    }
    void set(int i, int x){
        un.pb(i);
        a[i] = x;
    }
    int get(int i){
        return a[i];
    }
    void clear(){
        for(int i: un)
            a[i] = inf;
        a[0] = 0;
        un.clear();
    }
} a;
 
void dfs(int v, int p){
    if(r[v]) {
        sub[v] = 0;
        return;
    }
 
    sub[v] = 1;
    for(auto[u, w]: adj[v]){
        if(u==p)
            continue;
        dfs(u, v);
        sub[v] += sub[u];
    }
}
 
int get_centroid(int v, int p, int sz){
    for(auto[u, _]: adj[v])
        if(!r[u]&&u!=p&&sub[u]*2>sz)
            return get_centroid(u, v, sz);
    return v;
}
 
void upd_ans(int v, int p, ll dis, int dep){
    if(r[v]||dis>k)
        return;
    ans = min(ans, a.get(k-dis)+dep);
    for(auto[u, w]: adj[v])
        if(u!=p)
            upd_ans(u, v, dis+w, dep+1);
}
 
void upd_a(int v, int p, ll dis, int dep){
    if(r[v]||dis>k)
        return;
    a.set(dis, min(a.get(dis), dep));
    for(auto[u, w]: adj[v])
        if(u!=p)
            upd_a(u, v, dis+w, dep+1);
}
 
void solve(int v){
    if(r[v])
        return;
    dfs(v, -1);
    int c = get_centroid(v, -1, sub[v]);
    r[c] = 1;
    a.clear();
    for(auto[u, w]: adj[c]){
        upd_ans(u, c, w, 1);
        upd_a(u, c, w, 1);
    }
    for(auto[u, _]: adj[c])
        solve(u);
}
 
int best_path(int _n, int _k, int h[][2], int l[]) {
    n = _n;
    k = _k;
    for(int i = 0; i +1 < n; ++i) {
        adj[h[i][0]].eb(h[i][1], l[i]);
        adj[h[i][1]].eb(h[i][0], l[i]);
    }
    solve(0);
    if(ans==inf)
        return -1;
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 4 ms 8916 KB Output is correct
4 Correct 5 ms 8916 KB Output is correct
5 Correct 5 ms 8916 KB Output is correct
6 Correct 6 ms 8936 KB Output is correct
7 Correct 4 ms 8896 KB Output is correct
8 Correct 4 ms 8916 KB Output is correct
9 Correct 4 ms 8916 KB Output is correct
10 Correct 4 ms 8916 KB Output is correct
11 Correct 4 ms 8916 KB Output is correct
12 Correct 4 ms 8900 KB Output is correct
13 Correct 4 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 4 ms 8916 KB Output is correct
16 Correct 5 ms 8916 KB Output is correct
17 Correct 4 ms 8916 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 4 ms 8916 KB Output is correct
4 Correct 5 ms 8916 KB Output is correct
5 Correct 5 ms 8916 KB Output is correct
6 Correct 6 ms 8936 KB Output is correct
7 Correct 4 ms 8896 KB Output is correct
8 Correct 4 ms 8916 KB Output is correct
9 Correct 4 ms 8916 KB Output is correct
10 Correct 4 ms 8916 KB Output is correct
11 Correct 4 ms 8916 KB Output is correct
12 Correct 4 ms 8900 KB Output is correct
13 Correct 4 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 4 ms 8916 KB Output is correct
16 Correct 5 ms 8916 KB Output is correct
17 Correct 4 ms 8916 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
19 Correct 4 ms 8916 KB Output is correct
20 Correct 4 ms 8916 KB Output is correct
21 Correct 5 ms 8916 KB Output is correct
22 Correct 5 ms 8916 KB Output is correct
23 Correct 5 ms 8916 KB Output is correct
24 Correct 6 ms 8916 KB Output is correct
25 Correct 5 ms 8916 KB Output is correct
26 Correct 5 ms 8916 KB Output is correct
27 Correct 5 ms 8916 KB Output is correct
28 Correct 5 ms 8916 KB Output is correct
29 Correct 5 ms 8976 KB Output is correct
30 Correct 7 ms 8916 KB Output is correct
31 Correct 5 ms 8916 KB Output is correct
32 Correct 5 ms 8916 KB Output is correct
33 Correct 5 ms 8916 KB Output is correct
34 Correct 6 ms 8916 KB Output is correct
35 Correct 5 ms 9008 KB Output is correct
36 Correct 5 ms 8916 KB Output is correct
37 Correct 6 ms 8916 KB Output is correct
38 Correct 5 ms 8916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 4 ms 8916 KB Output is correct
4 Correct 5 ms 8916 KB Output is correct
5 Correct 5 ms 8916 KB Output is correct
6 Correct 6 ms 8936 KB Output is correct
7 Correct 4 ms 8896 KB Output is correct
8 Correct 4 ms 8916 KB Output is correct
9 Correct 4 ms 8916 KB Output is correct
10 Correct 4 ms 8916 KB Output is correct
11 Correct 4 ms 8916 KB Output is correct
12 Correct 4 ms 8900 KB Output is correct
13 Correct 4 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 4 ms 8916 KB Output is correct
16 Correct 5 ms 8916 KB Output is correct
17 Correct 4 ms 8916 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
19 Correct 105 ms 14300 KB Output is correct
20 Correct 109 ms 14212 KB Output is correct
21 Correct 128 ms 14508 KB Output is correct
22 Correct 110 ms 14864 KB Output is correct
23 Correct 69 ms 14368 KB Output is correct
24 Correct 55 ms 14304 KB Output is correct
25 Correct 116 ms 17772 KB Output is correct
26 Correct 101 ms 22004 KB Output is correct
27 Correct 159 ms 19584 KB Output is correct
28 Correct 241 ms 33864 KB Output is correct
29 Correct 294 ms 32780 KB Output is correct
30 Correct 164 ms 19676 KB Output is correct
31 Correct 155 ms 19660 KB Output is correct
32 Correct 183 ms 19668 KB Output is correct
33 Correct 225 ms 18520 KB Output is correct
34 Correct 170 ms 18488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 4 ms 8916 KB Output is correct
4 Correct 5 ms 8916 KB Output is correct
5 Correct 5 ms 8916 KB Output is correct
6 Correct 6 ms 8936 KB Output is correct
7 Correct 4 ms 8896 KB Output is correct
8 Correct 4 ms 8916 KB Output is correct
9 Correct 4 ms 8916 KB Output is correct
10 Correct 4 ms 8916 KB Output is correct
11 Correct 4 ms 8916 KB Output is correct
12 Correct 4 ms 8900 KB Output is correct
13 Correct 4 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 4 ms 8916 KB Output is correct
16 Correct 5 ms 8916 KB Output is correct
17 Correct 4 ms 8916 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
19 Correct 4 ms 8916 KB Output is correct
20 Correct 4 ms 8916 KB Output is correct
21 Correct 5 ms 8916 KB Output is correct
22 Correct 5 ms 8916 KB Output is correct
23 Correct 5 ms 8916 KB Output is correct
24 Correct 6 ms 8916 KB Output is correct
25 Correct 5 ms 8916 KB Output is correct
26 Correct 5 ms 8916 KB Output is correct
27 Correct 5 ms 8916 KB Output is correct
28 Correct 5 ms 8916 KB Output is correct
29 Correct 5 ms 8976 KB Output is correct
30 Correct 7 ms 8916 KB Output is correct
31 Correct 5 ms 8916 KB Output is correct
32 Correct 5 ms 8916 KB Output is correct
33 Correct 5 ms 8916 KB Output is correct
34 Correct 6 ms 8916 KB Output is correct
35 Correct 5 ms 9008 KB Output is correct
36 Correct 5 ms 8916 KB Output is correct
37 Correct 6 ms 8916 KB Output is correct
38 Correct 5 ms 8916 KB Output is correct
39 Correct 105 ms 14300 KB Output is correct
40 Correct 109 ms 14212 KB Output is correct
41 Correct 128 ms 14508 KB Output is correct
42 Correct 110 ms 14864 KB Output is correct
43 Correct 69 ms 14368 KB Output is correct
44 Correct 55 ms 14304 KB Output is correct
45 Correct 116 ms 17772 KB Output is correct
46 Correct 101 ms 22004 KB Output is correct
47 Correct 159 ms 19584 KB Output is correct
48 Correct 241 ms 33864 KB Output is correct
49 Correct 294 ms 32780 KB Output is correct
50 Correct 164 ms 19676 KB Output is correct
51 Correct 155 ms 19660 KB Output is correct
52 Correct 183 ms 19668 KB Output is correct
53 Correct 225 ms 18520 KB Output is correct
54 Correct 170 ms 18488 KB Output is correct
55 Correct 12 ms 9428 KB Output is correct
56 Correct 14 ms 9556 KB Output is correct
57 Correct 76 ms 15052 KB Output is correct
58 Correct 35 ms 15236 KB Output is correct
59 Correct 97 ms 22072 KB Output is correct
60 Correct 411 ms 34372 KB Output is correct
61 Correct 171 ms 19936 KB Output is correct
62 Correct 188 ms 20760 KB Output is correct
63 Correct 251 ms 20788 KB Output is correct
64 Correct 497 ms 20500 KB Output is correct
65 Correct 207 ms 19460 KB Output is correct
66 Correct 358 ms 30096 KB Output is correct
67 Correct 125 ms 21660 KB Output is correct
68 Correct 263 ms 20384 KB Output is correct
69 Correct 258 ms 20516 KB Output is correct
70 Correct 259 ms 20124 KB Output is correct