Submission #348743

# Submission time Handle Problem Language Result Execution time Memory
348743 2021-01-15T15:56:50 Z parsabahrami Race (IOI11_race) C++17
21 / 100
3000 ms 18028 KB
// Call my Name and Save me from The Dark
#include <bits/stdc++.h>
#include "race.h"

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second

const int N = 2e5 + 10;
int S[N], M[N], n, k, ret = 1e9; vector<pii> adj[N]; unordered_map<int, int> mp;

void preDFS(int v, int p = -1) {
    S[v] = 1;
    for (pii u : adj[v]) {
        if (u.F != p && !M[u.F]) preDFS(u.F, v), S[v] += S[u.F];
    }
}

int centroid(int v, int s, int p = -1) {
    for (pii u : adj[v]) {
        if (!M[u.F] && u.F != p && 2 * S[u.F] > s) return centroid(u.F, s, v);
    }
    return v;
}

void add(int v, int iw, int p, int h = 1) {
   if (mp.count(iw)) mp[iw] = min(mp[iw], h);
   else mp[iw] = h;
   for (pii u : adj[v]) {
       if (!M[u.F] && u.F != p) add(u.F, iw + u.S, v, h + 1);
   }
}

void calc(int v, int iw, int p, int h = 1) {
    if (iw > k) return;
    if (iw == k) ret = min(ret, h);
    else if (mp.count(k - iw)) ret = min(ret, h + mp[k - iw]);
    for (pii u : adj[v]) {
        if (!M[u.F] && u.F != p) calc(u.F, iw + u.S, v, h + 1);
    }
}

void solve(int v) {
    for (pii u : adj[v]) {
        calc(u.F, u.S, v);
        add(u.F, u.S, v);
    }
}

void decompose(int v) {
    preDFS(v);
    v = centroid(v, S[v]);
    // solve
    solve(v);
    mp = {};
    M[v] = 1;
    for (pii u : adj[v]) if (!M[u.F]) decompose(u.F);
}

int best_path(int _n, int _k, int h[][2], int l[]) {
    n = _n, k = _k;
    for (int i = 0; i < n - 1; i++) {
        int u = h[i][0] + 1, v = h[i][1] + 1;
        adj[u].push_back({v, l[i]});
        adj[v].push_back({u, l[i]});
    }
    decompose(1);
    return ret == 1e9 ? -1 : ret;
}
/* 
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i < n; i++) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        u++, v++;
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }
    decompose(1);
    printf("%d\n", ret == 1e9 ? -1 : ret);
    return 0;
} */


# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 3 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 3 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 4 ms 5100 KB Output is correct
20 Correct 4 ms 5100 KB Output is correct
21 Correct 5 ms 5100 KB Output is correct
22 Correct 6 ms 5100 KB Output is correct
23 Correct 6 ms 5100 KB Output is correct
24 Correct 6 ms 5100 KB Output is correct
25 Correct 6 ms 5100 KB Output is correct
26 Correct 6 ms 5100 KB Output is correct
27 Correct 5 ms 5100 KB Output is correct
28 Correct 6 ms 5100 KB Output is correct
29 Correct 6 ms 5100 KB Output is correct
30 Correct 6 ms 5100 KB Output is correct
31 Correct 6 ms 5100 KB Output is correct
32 Correct 6 ms 5100 KB Output is correct
33 Correct 7 ms 5100 KB Output is correct
34 Correct 6 ms 5100 KB Output is correct
35 Correct 5 ms 5100 KB Output is correct
36 Correct 6 ms 5228 KB Output is correct
37 Correct 5 ms 5100 KB Output is correct
38 Correct 5 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 3 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 378 ms 10732 KB Output is correct
20 Correct 377 ms 10732 KB Output is correct
21 Correct 372 ms 10732 KB Output is correct
22 Correct 379 ms 10860 KB Output is correct
23 Correct 288 ms 11116 KB Output is correct
24 Correct 227 ms 10860 KB Output is correct
25 Correct 483 ms 14540 KB Output is correct
26 Correct 182 ms 18028 KB Output is correct
27 Execution timed out 3071 ms 16508 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 3 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 4 ms 5100 KB Output is correct
20 Correct 4 ms 5100 KB Output is correct
21 Correct 5 ms 5100 KB Output is correct
22 Correct 6 ms 5100 KB Output is correct
23 Correct 6 ms 5100 KB Output is correct
24 Correct 6 ms 5100 KB Output is correct
25 Correct 6 ms 5100 KB Output is correct
26 Correct 6 ms 5100 KB Output is correct
27 Correct 5 ms 5100 KB Output is correct
28 Correct 6 ms 5100 KB Output is correct
29 Correct 6 ms 5100 KB Output is correct
30 Correct 6 ms 5100 KB Output is correct
31 Correct 6 ms 5100 KB Output is correct
32 Correct 6 ms 5100 KB Output is correct
33 Correct 7 ms 5100 KB Output is correct
34 Correct 6 ms 5100 KB Output is correct
35 Correct 5 ms 5100 KB Output is correct
36 Correct 6 ms 5228 KB Output is correct
37 Correct 5 ms 5100 KB Output is correct
38 Correct 5 ms 5100 KB Output is correct
39 Correct 378 ms 10732 KB Output is correct
40 Correct 377 ms 10732 KB Output is correct
41 Correct 372 ms 10732 KB Output is correct
42 Correct 379 ms 10860 KB Output is correct
43 Correct 288 ms 11116 KB Output is correct
44 Correct 227 ms 10860 KB Output is correct
45 Correct 483 ms 14540 KB Output is correct
46 Correct 182 ms 18028 KB Output is correct
47 Execution timed out 3071 ms 16508 KB Time limit exceeded
48 Halted 0 ms 0 KB -