Submission #419966

# Submission time Handle Problem Language Result Execution time Memory
419966 2021-06-07T19:54:19 Z Return_0 Race (IOI11_race) C++17
100 / 100
604 ms 38788 KB
#include "race.h"

// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef int ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#ifdef SINA
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; }
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); }
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1); cout.flush();
#else
#define dbg(...) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< (x) << endl, 0
#define cl const ll
#define fr first
#define sc second
#define lc (v << 1)
#define rc (lc | 1)
#define mid ((l + r) >> 1)
#define All(x) (x).begin(), (x).end()

cl inf = sizeof(ll) == 4 ? (1e9 + 10) : (3e18), mod = 1e9 + 7, MOD = 998244353;

template <class A,class B> ostream& operator << (ostream& out,const pair<A,B>&a){return out<<'('<<a.first<<", "<<a.second<<')';}
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
  out<< '['; for (int i = -1; ++i < int(a.size());) out<< a[i] << (i + 1 < int(a.size()) ? ", " : ""); return out<<']'; }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;

cl mxn = 2e5 + 7, mxk = 1e6 + 7;

ll mn [mxk], sz [mxn], h [mxn], len [mxn], arr [mxn], ans, k, L, R;
vector <array <ll, 2>> adj [mxn];
bool visible [mxn], init;

void initialize () { init = true; memset(mn, 63, sizeof mn); }

ll plant (cl &v, cl &pr = -1) {
	sz[v] = 1;
	for (auto [u, w] : adj[v]) if (visible[u] && u != pr) sz[v] += plant(u, v);
	return sz[v];
}

inline ll find_centroid (ll v, cl &n, ll pr = -1) {
	for (ll i = 0; i < SZ(adj[v]); i++) {
		ll &u = adj[v][i][0];
		if (sz[u] << 1 > n && visible[u] && u != pr) pr = v, v = u, i = -1;
	}
	return v;
}

void dfs (cl &v, cl &pr) {
	if (len[v] > k) return;
	arr[R++] = v;
	ans = min(ans, h[v] + mn[k - len[v]]);
	for (auto [u, w] : adj[v]) if (visible[u] && u != pr) {
		h[u] = h[v] + 1; len[u] = len[v] + w;
		dfs(u, v);
	}
}

inline void upd () { for (; L < R; L++) { ll &v = arr[L]; mn[len[v]] = min(mn[len[v]], h[v]); } }
inline void rmv () { for (ll i = 0; i < R; i++) mn[len[arr[i]]] = inf; }

void centroid_decomposition (ll v = 0) {
	v = find_centroid(v, plant(v));
	L = 1; R = 1; arr[0] = v; h[v] = len[v] = 0; mn[0] = 0;
	for (auto [u, w] : adj[v]) if (visible[u]) {
		h[u] = 1; len[u] = w;
		dfs(u, v);
		upd();
	}
	rmv();
	visible[v] = false;
	for (auto [u, w] : adj[v]) if (visible[u]) centroid_decomposition(u);
}

int best_path(int N, int K, int H[][2], int L[]) {
	if (!init) initialize();
	ans = inf; k = K;
	for (ll i = 0; i < N; i++) adj[i].clear(), visible[i] = true;
	for (ll i = 0; i < N - 1; i++) adj[H[i][0]].push_back({H[i][1], L[i]}), adj[H[i][1]].push_back({H[i][0], L[i]});
	centroid_decomposition();
	if (ans >= inf) ans = -1;
	return ans;
}
/*

*/
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8908 KB Output is correct
2 Correct 5 ms 8908 KB Output is correct
3 Correct 5 ms 8908 KB Output is correct
4 Correct 5 ms 8960 KB Output is correct
5 Correct 5 ms 8908 KB Output is correct
6 Correct 5 ms 8908 KB Output is correct
7 Correct 7 ms 8848 KB Output is correct
8 Correct 5 ms 8908 KB Output is correct
9 Correct 5 ms 8908 KB Output is correct
10 Correct 5 ms 8848 KB Output is correct
11 Correct 5 ms 8844 KB Output is correct
12 Correct 5 ms 8908 KB Output is correct
13 Correct 5 ms 8908 KB Output is correct
14 Correct 6 ms 8908 KB Output is correct
15 Correct 5 ms 8908 KB Output is correct
16 Correct 6 ms 8908 KB Output is correct
17 Correct 5 ms 8908 KB Output is correct
18 Correct 5 ms 8876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8908 KB Output is correct
2 Correct 5 ms 8908 KB Output is correct
3 Correct 5 ms 8908 KB Output is correct
4 Correct 5 ms 8960 KB Output is correct
5 Correct 5 ms 8908 KB Output is correct
6 Correct 5 ms 8908 KB Output is correct
7 Correct 7 ms 8848 KB Output is correct
8 Correct 5 ms 8908 KB Output is correct
9 Correct 5 ms 8908 KB Output is correct
10 Correct 5 ms 8848 KB Output is correct
11 Correct 5 ms 8844 KB Output is correct
12 Correct 5 ms 8908 KB Output is correct
13 Correct 5 ms 8908 KB Output is correct
14 Correct 6 ms 8908 KB Output is correct
15 Correct 5 ms 8908 KB Output is correct
16 Correct 6 ms 8908 KB Output is correct
17 Correct 5 ms 8908 KB Output is correct
18 Correct 5 ms 8876 KB Output is correct
19 Correct 5 ms 8912 KB Output is correct
20 Correct 5 ms 8908 KB Output is correct
21 Correct 5 ms 8980 KB Output is correct
22 Correct 5 ms 8984 KB Output is correct
23 Correct 7 ms 8908 KB Output is correct
24 Correct 6 ms 8980 KB Output is correct
25 Correct 7 ms 8984 KB Output is correct
26 Correct 6 ms 8980 KB Output is correct
27 Correct 5 ms 8984 KB Output is correct
28 Correct 6 ms 8908 KB Output is correct
29 Correct 6 ms 8908 KB Output is correct
30 Correct 6 ms 8908 KB Output is correct
31 Correct 6 ms 8908 KB Output is correct
32 Correct 7 ms 8908 KB Output is correct
33 Correct 7 ms 8908 KB Output is correct
34 Correct 6 ms 8908 KB Output is correct
35 Correct 6 ms 8908 KB Output is correct
36 Correct 6 ms 9036 KB Output is correct
37 Correct 6 ms 8908 KB Output is correct
38 Correct 6 ms 8980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8908 KB Output is correct
2 Correct 5 ms 8908 KB Output is correct
3 Correct 5 ms 8908 KB Output is correct
4 Correct 5 ms 8960 KB Output is correct
5 Correct 5 ms 8908 KB Output is correct
6 Correct 5 ms 8908 KB Output is correct
7 Correct 7 ms 8848 KB Output is correct
8 Correct 5 ms 8908 KB Output is correct
9 Correct 5 ms 8908 KB Output is correct
10 Correct 5 ms 8848 KB Output is correct
11 Correct 5 ms 8844 KB Output is correct
12 Correct 5 ms 8908 KB Output is correct
13 Correct 5 ms 8908 KB Output is correct
14 Correct 6 ms 8908 KB Output is correct
15 Correct 5 ms 8908 KB Output is correct
16 Correct 6 ms 8908 KB Output is correct
17 Correct 5 ms 8908 KB Output is correct
18 Correct 5 ms 8876 KB Output is correct
19 Correct 153 ms 15060 KB Output is correct
20 Correct 169 ms 15196 KB Output is correct
21 Correct 196 ms 15260 KB Output is correct
22 Correct 219 ms 15504 KB Output is correct
23 Correct 102 ms 15452 KB Output is correct
24 Correct 73 ms 15164 KB Output is correct
25 Correct 174 ms 19644 KB Output is correct
26 Correct 127 ms 24344 KB Output is correct
27 Correct 210 ms 21452 KB Output is correct
28 Correct 334 ms 38788 KB Output is correct
29 Correct 331 ms 37356 KB Output is correct
30 Correct 216 ms 21400 KB Output is correct
31 Correct 195 ms 21432 KB Output is correct
32 Correct 252 ms 21444 KB Output is correct
33 Correct 303 ms 20500 KB Output is correct
34 Correct 232 ms 20292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8908 KB Output is correct
2 Correct 5 ms 8908 KB Output is correct
3 Correct 5 ms 8908 KB Output is correct
4 Correct 5 ms 8960 KB Output is correct
5 Correct 5 ms 8908 KB Output is correct
6 Correct 5 ms 8908 KB Output is correct
7 Correct 7 ms 8848 KB Output is correct
8 Correct 5 ms 8908 KB Output is correct
9 Correct 5 ms 8908 KB Output is correct
10 Correct 5 ms 8848 KB Output is correct
11 Correct 5 ms 8844 KB Output is correct
12 Correct 5 ms 8908 KB Output is correct
13 Correct 5 ms 8908 KB Output is correct
14 Correct 6 ms 8908 KB Output is correct
15 Correct 5 ms 8908 KB Output is correct
16 Correct 6 ms 8908 KB Output is correct
17 Correct 5 ms 8908 KB Output is correct
18 Correct 5 ms 8876 KB Output is correct
19 Correct 5 ms 8912 KB Output is correct
20 Correct 5 ms 8908 KB Output is correct
21 Correct 5 ms 8980 KB Output is correct
22 Correct 5 ms 8984 KB Output is correct
23 Correct 7 ms 8908 KB Output is correct
24 Correct 6 ms 8980 KB Output is correct
25 Correct 7 ms 8984 KB Output is correct
26 Correct 6 ms 8980 KB Output is correct
27 Correct 5 ms 8984 KB Output is correct
28 Correct 6 ms 8908 KB Output is correct
29 Correct 6 ms 8908 KB Output is correct
30 Correct 6 ms 8908 KB Output is correct
31 Correct 6 ms 8908 KB Output is correct
32 Correct 7 ms 8908 KB Output is correct
33 Correct 7 ms 8908 KB Output is correct
34 Correct 6 ms 8908 KB Output is correct
35 Correct 6 ms 8908 KB Output is correct
36 Correct 6 ms 9036 KB Output is correct
37 Correct 6 ms 8908 KB Output is correct
38 Correct 6 ms 8980 KB Output is correct
39 Correct 153 ms 15060 KB Output is correct
40 Correct 169 ms 15196 KB Output is correct
41 Correct 196 ms 15260 KB Output is correct
42 Correct 219 ms 15504 KB Output is correct
43 Correct 102 ms 15452 KB Output is correct
44 Correct 73 ms 15164 KB Output is correct
45 Correct 174 ms 19644 KB Output is correct
46 Correct 127 ms 24344 KB Output is correct
47 Correct 210 ms 21452 KB Output is correct
48 Correct 334 ms 38788 KB Output is correct
49 Correct 331 ms 37356 KB Output is correct
50 Correct 216 ms 21400 KB Output is correct
51 Correct 195 ms 21432 KB Output is correct
52 Correct 252 ms 21444 KB Output is correct
53 Correct 303 ms 20500 KB Output is correct
54 Correct 232 ms 20292 KB Output is correct
55 Correct 14 ms 9548 KB Output is correct
56 Correct 16 ms 9548 KB Output is correct
57 Correct 108 ms 15744 KB Output is correct
58 Correct 57 ms 15684 KB Output is correct
59 Correct 125 ms 24352 KB Output is correct
60 Correct 554 ms 38784 KB Output is correct
61 Correct 201 ms 21628 KB Output is correct
62 Correct 297 ms 22100 KB Output is correct
63 Correct 354 ms 22276 KB Output is correct
64 Correct 604 ms 22084 KB Output is correct
65 Correct 336 ms 21380 KB Output is correct
66 Correct 539 ms 34340 KB Output is correct
67 Correct 157 ms 22412 KB Output is correct
68 Correct 336 ms 22032 KB Output is correct
69 Correct 355 ms 22184 KB Output is correct
70 Correct 301 ms 21404 KB Output is correct