답안 #647467

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647467 2022-10-02T16:17:22 Z tamthegod 경주 (Race) (IOI11_race) C++14
100 / 100
766 ms 54732 KB
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<bitset>
#include<chrono>
#include<random>
#include<ext/rope>
/* ordered_set
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e9;
int n, k;
vector<pair<int, int>> adj[maxN];
int vis[maxN];
int sz[maxN], parCent[maxN];
int f[maxN];
int res = oo;
int dfs(int u, int par)
{
    sz[u] = 1;
    for(auto a : adj[u])
    {
        int v = a.fi;
        if(v == par || vis[v]) continue;
        sz[u] += dfs(v, u);
    }
    return sz[u];
}
int Find_Centroid(int u, int par, int val)
{
    for(auto a : adj[u])
    {
        int v = a.fi;
        if(v == par || vis[v]) continue;
        if(sz[v] > val / 2) return Find_Centroid(v, u, val);
    }
    return u;
}
int get(int u, int par, int d, int cnt)
{
    if(d > k) return oo;
    int res = f[k - d] + cnt;
    for(auto a : adj[u])
    {
        int v = a.fi, w = a.se;
        if(v == par || vis[v] || d + w > k) continue;
        res = min(res, get(v, u, d + w, cnt + 1));
    }
    return res;
}
void add(int u, int par, int d, int cnt)
{
    if(d > k) return;
    f[d] = min(f[d], cnt);
    for(auto a : adj[u])
    {
        int v = a.fi, w = a.se;
        if(v == par || vis[v] || d + w > k) continue;
        add(v, u, d + w, cnt + 1);
    }
}
void del(int u, int par, int d)
{
    if(d > k) return;
    f[d] = oo;
    for(auto a : adj[u])
    {
        int v = a.fi, w = a.se;
        if(v == par || vis[v] || d + w > k) continue;
        del(v, u, d + w);
    }
}
int Decompose(int u)
{
    int root = Find_Centroid(u, 0, dfs(u, 0));
    vis[root] = -1;
    f[0] = 0;
    for(auto a : adj[root])
    {
        int v = a.fi, w = a.se;
        if(vis[v]) continue;
        res = min(res, get(v, root, w, 1));
        add(v, root, w, 1);
    }
    del(root, -1, 0);
    for(auto a : adj[root])
    {
        int v = a.fi;
        if(vis[v]) continue;
        parCent[Decompose(v)] = root;
    }
    return root;
}
int best_path(int N, int K, int H[][2], int L[2])
{
    n = N;
    k = K;
    for(int i=0; i<n; i++)
    {
        H[i][0]++;
        H[i][1]++;
        adj[H[i][0]].pb({H[i][1], L[i]});
        adj[H[i][1]].pb({H[i][0], L[i]});
    }
    fill(f, f + maxN, oo);
    Decompose(1);
    return (res < oo ? res : -1);
}
void ReadInput()
{
    cin >> n >> k;
    for(int i=1; i<n; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        u++;
        v++;
        adj[u].pb({v, w});
        adj[v].pb({u, w});
    }
}

/*int main()
{
    freopen("x.inp", "r", stdin);
    ReadInput();
    Solve();
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27732 KB Output is correct
2 Correct 15 ms 27720 KB Output is correct
3 Correct 15 ms 27628 KB Output is correct
4 Correct 15 ms 27708 KB Output is correct
5 Correct 14 ms 27748 KB Output is correct
6 Correct 15 ms 27744 KB Output is correct
7 Correct 15 ms 27748 KB Output is correct
8 Correct 14 ms 27640 KB Output is correct
9 Correct 15 ms 27732 KB Output is correct
10 Correct 15 ms 27732 KB Output is correct
11 Correct 14 ms 27732 KB Output is correct
12 Correct 15 ms 27732 KB Output is correct
13 Correct 16 ms 27716 KB Output is correct
14 Correct 15 ms 27688 KB Output is correct
15 Correct 16 ms 27664 KB Output is correct
16 Correct 15 ms 27700 KB Output is correct
17 Correct 15 ms 27732 KB Output is correct
18 Correct 14 ms 27732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27732 KB Output is correct
2 Correct 15 ms 27720 KB Output is correct
3 Correct 15 ms 27628 KB Output is correct
4 Correct 15 ms 27708 KB Output is correct
5 Correct 14 ms 27748 KB Output is correct
6 Correct 15 ms 27744 KB Output is correct
7 Correct 15 ms 27748 KB Output is correct
8 Correct 14 ms 27640 KB Output is correct
9 Correct 15 ms 27732 KB Output is correct
10 Correct 15 ms 27732 KB Output is correct
11 Correct 14 ms 27732 KB Output is correct
12 Correct 15 ms 27732 KB Output is correct
13 Correct 16 ms 27716 KB Output is correct
14 Correct 15 ms 27688 KB Output is correct
15 Correct 16 ms 27664 KB Output is correct
16 Correct 15 ms 27700 KB Output is correct
17 Correct 15 ms 27732 KB Output is correct
18 Correct 14 ms 27732 KB Output is correct
19 Correct 16 ms 27660 KB Output is correct
20 Correct 14 ms 27732 KB Output is correct
21 Correct 17 ms 27748 KB Output is correct
22 Correct 16 ms 27680 KB Output is correct
23 Correct 19 ms 27732 KB Output is correct
24 Correct 17 ms 27732 KB Output is correct
25 Correct 15 ms 27776 KB Output is correct
26 Correct 15 ms 27756 KB Output is correct
27 Correct 16 ms 27792 KB Output is correct
28 Correct 15 ms 27796 KB Output is correct
29 Correct 16 ms 27732 KB Output is correct
30 Correct 16 ms 27732 KB Output is correct
31 Correct 16 ms 27732 KB Output is correct
32 Correct 20 ms 27732 KB Output is correct
33 Correct 16 ms 27732 KB Output is correct
34 Correct 19 ms 27684 KB Output is correct
35 Correct 16 ms 27720 KB Output is correct
36 Correct 15 ms 27732 KB Output is correct
37 Correct 15 ms 27744 KB Output is correct
38 Correct 15 ms 27748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27732 KB Output is correct
2 Correct 15 ms 27720 KB Output is correct
3 Correct 15 ms 27628 KB Output is correct
4 Correct 15 ms 27708 KB Output is correct
5 Correct 14 ms 27748 KB Output is correct
6 Correct 15 ms 27744 KB Output is correct
7 Correct 15 ms 27748 KB Output is correct
8 Correct 14 ms 27640 KB Output is correct
9 Correct 15 ms 27732 KB Output is correct
10 Correct 15 ms 27732 KB Output is correct
11 Correct 14 ms 27732 KB Output is correct
12 Correct 15 ms 27732 KB Output is correct
13 Correct 16 ms 27716 KB Output is correct
14 Correct 15 ms 27688 KB Output is correct
15 Correct 16 ms 27664 KB Output is correct
16 Correct 15 ms 27700 KB Output is correct
17 Correct 15 ms 27732 KB Output is correct
18 Correct 14 ms 27732 KB Output is correct
19 Correct 183 ms 33728 KB Output is correct
20 Correct 161 ms 33612 KB Output is correct
21 Correct 192 ms 33860 KB Output is correct
22 Correct 183 ms 33740 KB Output is correct
23 Correct 91 ms 34104 KB Output is correct
24 Correct 70 ms 33800 KB Output is correct
25 Correct 150 ms 36560 KB Output is correct
26 Correct 117 ms 40688 KB Output is correct
27 Correct 225 ms 42900 KB Output is correct
28 Correct 316 ms 54348 KB Output is correct
29 Correct 339 ms 53332 KB Output is correct
30 Correct 190 ms 42892 KB Output is correct
31 Correct 192 ms 42828 KB Output is correct
32 Correct 267 ms 42964 KB Output is correct
33 Correct 267 ms 41684 KB Output is correct
34 Correct 203 ms 42604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27732 KB Output is correct
2 Correct 15 ms 27720 KB Output is correct
3 Correct 15 ms 27628 KB Output is correct
4 Correct 15 ms 27708 KB Output is correct
5 Correct 14 ms 27748 KB Output is correct
6 Correct 15 ms 27744 KB Output is correct
7 Correct 15 ms 27748 KB Output is correct
8 Correct 14 ms 27640 KB Output is correct
9 Correct 15 ms 27732 KB Output is correct
10 Correct 15 ms 27732 KB Output is correct
11 Correct 14 ms 27732 KB Output is correct
12 Correct 15 ms 27732 KB Output is correct
13 Correct 16 ms 27716 KB Output is correct
14 Correct 15 ms 27688 KB Output is correct
15 Correct 16 ms 27664 KB Output is correct
16 Correct 15 ms 27700 KB Output is correct
17 Correct 15 ms 27732 KB Output is correct
18 Correct 14 ms 27732 KB Output is correct
19 Correct 16 ms 27660 KB Output is correct
20 Correct 14 ms 27732 KB Output is correct
21 Correct 17 ms 27748 KB Output is correct
22 Correct 16 ms 27680 KB Output is correct
23 Correct 19 ms 27732 KB Output is correct
24 Correct 17 ms 27732 KB Output is correct
25 Correct 15 ms 27776 KB Output is correct
26 Correct 15 ms 27756 KB Output is correct
27 Correct 16 ms 27792 KB Output is correct
28 Correct 15 ms 27796 KB Output is correct
29 Correct 16 ms 27732 KB Output is correct
30 Correct 16 ms 27732 KB Output is correct
31 Correct 16 ms 27732 KB Output is correct
32 Correct 20 ms 27732 KB Output is correct
33 Correct 16 ms 27732 KB Output is correct
34 Correct 19 ms 27684 KB Output is correct
35 Correct 16 ms 27720 KB Output is correct
36 Correct 15 ms 27732 KB Output is correct
37 Correct 15 ms 27744 KB Output is correct
38 Correct 15 ms 27748 KB Output is correct
39 Correct 183 ms 33728 KB Output is correct
40 Correct 161 ms 33612 KB Output is correct
41 Correct 192 ms 33860 KB Output is correct
42 Correct 183 ms 33740 KB Output is correct
43 Correct 91 ms 34104 KB Output is correct
44 Correct 70 ms 33800 KB Output is correct
45 Correct 150 ms 36560 KB Output is correct
46 Correct 117 ms 40688 KB Output is correct
47 Correct 225 ms 42900 KB Output is correct
48 Correct 316 ms 54348 KB Output is correct
49 Correct 339 ms 53332 KB Output is correct
50 Correct 190 ms 42892 KB Output is correct
51 Correct 192 ms 42828 KB Output is correct
52 Correct 267 ms 42964 KB Output is correct
53 Correct 267 ms 41684 KB Output is correct
54 Correct 203 ms 42604 KB Output is correct
55 Correct 28 ms 28372 KB Output is correct
56 Correct 34 ms 28408 KB Output is correct
57 Correct 127 ms 35276 KB Output is correct
58 Correct 51 ms 34984 KB Output is correct
59 Correct 120 ms 41756 KB Output is correct
60 Correct 659 ms 54732 KB Output is correct
61 Correct 215 ms 43028 KB Output is correct
62 Correct 272 ms 43016 KB Output is correct
63 Correct 416 ms 42976 KB Output is correct
64 Correct 766 ms 43332 KB Output is correct
65 Correct 310 ms 43772 KB Output is correct
66 Correct 439 ms 51424 KB Output is correct
67 Correct 213 ms 43572 KB Output is correct
68 Correct 335 ms 43716 KB Output is correct
69 Correct 329 ms 43832 KB Output is correct
70 Correct 329 ms 43112 KB Output is correct