Submission #713332

# Submission time Handle Problem Language Result Execution time Memory
713332 2023-03-21T17:15:38 Z Spade1 Race (IOI11_race) C++14
100 / 100
1025 ms 41916 KB
#include <bits/stdc++.h>
#include "race.h"
//#include "grader.cpp"
#define pii pair<int, int>
#define pb push_back
#define st first
#define nd second
using namespace std;

const int maxN = 2e5 + 10;
const int maxL = 1e6 + 10;

vector<pii> adj[maxN];
set<int> s;
int sz[maxN], mn = INT_MAX, k, path[maxL];
bool mark[maxN];

int dfs(int i, int prt=0) {
    sz[i] = 1;
    for (auto [j, w] : adj[i]) {
        if (j == prt || mark[j]) continue;
        sz[i] += dfs(j, i);
    }
    return sz[i];
}

int find_centroid(int i, int n, int prt=0) {
    for (auto [j, w] : adj[i]) {
        if (j == prt || mark[j]) continue;
        if (sz[j] > n/2) return find_centroid(j, n, i);
    }
    return i;
}

void dfs2(int i, int prt, bool filling, int dis, int cnt=1) {
    if (dis > k) return;
    s.insert(dis);
    if (filling) path[dis] = min(path[dis], cnt);
    else if (path[k-dis] != INT_MAX) mn = min(mn, cnt+path[k-dis]);
    for (auto [j, w] : adj[i]) {
        if (j == prt || mark[j]) continue;
        dfs2(j, i, filling, dis+w, cnt+1);
    }
}

void decom(int x=0) {
    int cen = find_centroid(x, dfs(x));
    mark[cen] = 1;

    for (auto [j, w] : adj[cen]) {
        if (mark[j]) continue;
        dfs2(j, cen, 0, w);
        dfs2(j, cen, 1, w);
    }
    for (auto i : s) {
        path[i] = INT_MAX;
    }
    s.clear();
    for (auto [j, w] : adj[cen]) {
        if (!mark[j]) decom(j);
    }
}

int best_path(int N, int K, int H[][2], int L[]) {
    k = K;
    for (int i = 0; i < N-1; ++i) {
        adj[H[i][0]].pb({H[i][1], L[i]});
        adj[H[i][1]].pb({H[i][0], L[i]});
    }
    for (int i = 1; i < maxL; ++i) path[i] = INT_MAX;
    path[0] = 0;
    decom();
    return (mn == INT_MAX ? -1 : mn);
}

Compilation message

race.cpp: In function 'int dfs(int, int)':
race.cpp:20:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   20 |     for (auto [j, w] : adj[i]) {
      |               ^
race.cpp: In function 'int find_centroid(int, int, int)':
race.cpp:28:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   28 |     for (auto [j, w] : adj[i]) {
      |               ^
race.cpp: In function 'void dfs2(int, int, bool, int, int)':
race.cpp:40:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |     for (auto [j, w] : adj[i]) {
      |               ^
race.cpp: In function 'void decom(int)':
race.cpp:50:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |     for (auto [j, w] : adj[cen]) {
      |               ^
race.cpp:59:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   59 |     for (auto [j, w] : adj[cen]) {
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 6 ms 8820 KB Output is correct
3 Correct 7 ms 8916 KB Output is correct
4 Correct 4 ms 8916 KB Output is correct
5 Correct 4 ms 8916 KB Output is correct
6 Correct 4 ms 8916 KB Output is correct
7 Correct 4 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8928 KB Output is correct
10 Correct 5 ms 8916 KB Output is correct
11 Correct 5 ms 8916 KB Output is correct
12 Correct 7 ms 8916 KB Output is correct
13 Correct 5 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 5 ms 8824 KB Output is correct
16 Correct 7 ms 8916 KB Output is correct
17 Correct 5 ms 8916 KB Output is correct
18 Correct 6 ms 8916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 6 ms 8820 KB Output is correct
3 Correct 7 ms 8916 KB Output is correct
4 Correct 4 ms 8916 KB Output is correct
5 Correct 4 ms 8916 KB Output is correct
6 Correct 4 ms 8916 KB Output is correct
7 Correct 4 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8928 KB Output is correct
10 Correct 5 ms 8916 KB Output is correct
11 Correct 5 ms 8916 KB Output is correct
12 Correct 7 ms 8916 KB Output is correct
13 Correct 5 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 5 ms 8824 KB Output is correct
16 Correct 7 ms 8916 KB Output is correct
17 Correct 5 ms 8916 KB Output is correct
18 Correct 6 ms 8916 KB Output is correct
19 Correct 5 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 6 ms 8916 KB Output is correct
24 Correct 6 ms 8916 KB Output is correct
25 Correct 6 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 6 ms 8940 KB Output is correct
30 Correct 6 ms 8916 KB Output is correct
31 Correct 6 ms 8916 KB Output is correct
32 Correct 7 ms 8916 KB Output is correct
33 Correct 6 ms 8916 KB Output is correct
34 Correct 6 ms 8916 KB Output is correct
35 Correct 7 ms 8916 KB Output is correct
36 Correct 7 ms 8916 KB Output is correct
37 Correct 7 ms 8916 KB Output is correct
38 Correct 7 ms 8916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 6 ms 8820 KB Output is correct
3 Correct 7 ms 8916 KB Output is correct
4 Correct 4 ms 8916 KB Output is correct
5 Correct 4 ms 8916 KB Output is correct
6 Correct 4 ms 8916 KB Output is correct
7 Correct 4 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8928 KB Output is correct
10 Correct 5 ms 8916 KB Output is correct
11 Correct 5 ms 8916 KB Output is correct
12 Correct 7 ms 8916 KB Output is correct
13 Correct 5 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 5 ms 8824 KB Output is correct
16 Correct 7 ms 8916 KB Output is correct
17 Correct 5 ms 8916 KB Output is correct
18 Correct 6 ms 8916 KB Output is correct
19 Correct 153 ms 14156 KB Output is correct
20 Correct 173 ms 15592 KB Output is correct
21 Correct 200 ms 15676 KB Output is correct
22 Correct 170 ms 15712 KB Output is correct
23 Correct 80 ms 15932 KB Output is correct
24 Correct 82 ms 15824 KB Output is correct
25 Correct 160 ms 18388 KB Output is correct
26 Correct 99 ms 21196 KB Output is correct
27 Correct 197 ms 22600 KB Output is correct
28 Correct 278 ms 34048 KB Output is correct
29 Correct 246 ms 33148 KB Output is correct
30 Correct 193 ms 22692 KB Output is correct
31 Correct 207 ms 22684 KB Output is correct
32 Correct 235 ms 22816 KB Output is correct
33 Correct 245 ms 21612 KB Output is correct
34 Correct 174 ms 22476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 6 ms 8820 KB Output is correct
3 Correct 7 ms 8916 KB Output is correct
4 Correct 4 ms 8916 KB Output is correct
5 Correct 4 ms 8916 KB Output is correct
6 Correct 4 ms 8916 KB Output is correct
7 Correct 4 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8928 KB Output is correct
10 Correct 5 ms 8916 KB Output is correct
11 Correct 5 ms 8916 KB Output is correct
12 Correct 7 ms 8916 KB Output is correct
13 Correct 5 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 5 ms 8824 KB Output is correct
16 Correct 7 ms 8916 KB Output is correct
17 Correct 5 ms 8916 KB Output is correct
18 Correct 6 ms 8916 KB Output is correct
19 Correct 5 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 6 ms 8916 KB Output is correct
24 Correct 6 ms 8916 KB Output is correct
25 Correct 6 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 6 ms 8940 KB Output is correct
30 Correct 6 ms 8916 KB Output is correct
31 Correct 6 ms 8916 KB Output is correct
32 Correct 7 ms 8916 KB Output is correct
33 Correct 6 ms 8916 KB Output is correct
34 Correct 6 ms 8916 KB Output is correct
35 Correct 7 ms 8916 KB Output is correct
36 Correct 7 ms 8916 KB Output is correct
37 Correct 7 ms 8916 KB Output is correct
38 Correct 7 ms 8916 KB Output is correct
39 Correct 153 ms 14156 KB Output is correct
40 Correct 173 ms 15592 KB Output is correct
41 Correct 200 ms 15676 KB Output is correct
42 Correct 170 ms 15712 KB Output is correct
43 Correct 80 ms 15932 KB Output is correct
44 Correct 82 ms 15824 KB Output is correct
45 Correct 160 ms 18388 KB Output is correct
46 Correct 99 ms 21196 KB Output is correct
47 Correct 197 ms 22600 KB Output is correct
48 Correct 278 ms 34048 KB Output is correct
49 Correct 246 ms 33148 KB Output is correct
50 Correct 193 ms 22692 KB Output is correct
51 Correct 207 ms 22684 KB Output is correct
52 Correct 235 ms 22816 KB Output is correct
53 Correct 245 ms 21612 KB Output is correct
54 Correct 174 ms 22476 KB Output is correct
55 Correct 20 ms 9800 KB Output is correct
56 Correct 18 ms 9504 KB Output is correct
57 Correct 158 ms 15788 KB Output is correct
58 Correct 41 ms 15524 KB Output is correct
59 Correct 258 ms 24916 KB Output is correct
60 Correct 952 ms 41916 KB Output is correct
61 Correct 251 ms 23048 KB Output is correct
62 Correct 292 ms 22936 KB Output is correct
63 Correct 338 ms 23012 KB Output is correct
64 Correct 1025 ms 27704 KB Output is correct
65 Correct 213 ms 23692 KB Output is correct
66 Correct 630 ms 31524 KB Output is correct
67 Correct 115 ms 23428 KB Output is correct
68 Correct 421 ms 27124 KB Output is correct
69 Correct 386 ms 27136 KB Output is correct
70 Correct 370 ms 26440 KB Output is correct