# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1080951 |
2024-08-29T16:15:21 Z |
duduFreire |
Race (IOI11_race) |
C++17 |
|
1360 ms |
82856 KB |
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for(ll i=(ll)(a);i < (ll)(b);i++)
#define pii pair<ll, ll>
#define vi vector<ll>
#define vvi vector<vi>
#define sz(x) ((ll)(x).size())
#ifdef LOCAL
#define debug(var) cerr << #var << ": " << var << endl
#else
#define debug(var)
#endif
using namespace std;
template<class T, class U> auto &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; }
template<class T, class U> auto &operator<<(ostream &os, pair<T, U> const& p) { return os << '{' << p.first << ' ' << p.second << '}'; }
const auto ES = "", SEP = " ";
template<class T> auto &operator>>(istream& is, vector<T> &c) { for (auto &x : c) is >> x; return is; }
template<class T> auto &operator<<(ostream& os, vector<T> const &c) { auto sep = ES; for (auto x : c) os << sep << x, sep = SEP; return os; }
template<class T> auto &operator<<(ostream& os, set<T> const &c) { auto sep = ES; for (auto x : c) os << sep << x, sep = SEP; return os; }
template<class T> auto &operator<<(ostream& os, multiset<T> const &c) { auto sep = ES; for (auto x : c) os << sep << x, sep = SEP; return os; }
template<class T> auto &operator<<(ostream& os, unordered_set<T> const &c) { auto sep = ES; for (auto x : c) os << sep << x, sep = SEP; return os; }
template<class T> auto &operator<<(ostream& os, deque<T> const &c) { auto sep = ES; for (auto x : c) os << sep << x, sep = SEP; return os; }
template<class K, class V> auto &operator<<(ostream& os, map<K,V> const &c) { auto sep = ES; for (auto x : c) os << sep << x, sep = SEP; return os; }
template<class K, class V> auto &operator<<(ostream& os, unordered_map<K,V> const &c) { auto sep = ES; for (auto x : c) os << sep << x, sep = SEP; return os; }
ll ceil(ll a, ll b) {
return (a+b-1)/b;
}
constexpr ll MAX=2e5;
constexpr ll MOD=1e9+7;
constexpr ll oo=0x3f3f3f3f3f3f3f3f;
/*
*/
ll k;
struct Centroid {
vector<vector<pii>> g;
ll rt, n;
vi rmv, ssz, par;
ll ans=oo;
Centroid(vector<vector<pii>> ag, ll art) : g(ag), rt(art), n(g.size()), rmv(n,0), ssz(n,0), par(n,0) {
centroid_tree(art);
}
ll sizes(ll a, ll p=-1) {
ll ans=1;
for(auto&[b,w]:g[a]) {
if (b == p or rmv[b]) continue;
ans+=sizes(b,a);
}
return ssz[a]=ans;
}
void calcdists(ll a, ll d, ll p, vi& dists) {
dists[d]++;
for(auto&[b,w] : g[a]) {
if (rmv[b] or b==p) continue;
calcdists(b, d+1, a,dists);
}
}
ll centroid(ll a, ll tsize, ll p=-1) {
for(auto&[b,w]:g[a]) {
if (rmv[b] or b==p) continue;
if (ssz[b] * 2 > tsize) return centroid(b,tsize, a);
}
return a;
}
void centroid_tree(ll a, ll p=-1) {
ll c=centroid(a, sizes(a));
rmv[c]=true;
par[c]=p;
solvesub(c);
for(auto&[b,w] : g[c]) {
if (rmv[b]) continue;
centroid_tree(b, c);
}
}
// do not visit removed guys (if rmv[b] continue)
void solvesub(ll a) {
map<ll,ll> best, rbest;
auto dfs=[&](auto self, ll a, ll sum, ll h, ll p) -> void {
if (sum <= k) {
if (!rbest.count(sum) or rbest[sum] > h) rbest[sum]=h;
}
for (auto [b,w] : g[a]) if (!rmv[b] and b!=p) {
self(self,b,sum+w,h+1,a);
}
};
best[0]=0;
for (auto& [b,w] : g[a]) if (!rmv[b]) {
dfs(dfs, b, w, 1, a);
for (auto [val, h] : rbest) {
if (best.count(k-val)) {
ans=min(ans, best[k-val]+h);
}
}
for (auto [val, h] : rbest)
if (!best.count(val) or best[val] > h) best[val]=h;
map<ll,ll> gbg; swap(rbest, gbg);
}
}
};
int best_path(int n, int ak, int h[][2], int l[]) {
k=ak;
vector<vector<pii>> g(n);
rep(i,0,n-1) {
g[h[i][0]].eb(h[i][1],l[i]);
g[h[i][1]].eb(h[i][0],l[i]);
}
Centroid centroid(g, 0);
return centroid.ans == oo ? -1 : centroid.ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
724 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
712 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
2 ms |
600 KB |
Output is correct |
38 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
181 ms |
26672 KB |
Output is correct |
20 |
Correct |
200 ms |
26708 KB |
Output is correct |
21 |
Correct |
179 ms |
26848 KB |
Output is correct |
22 |
Correct |
162 ms |
26708 KB |
Output is correct |
23 |
Correct |
130 ms |
27220 KB |
Output is correct |
24 |
Correct |
90 ms |
26460 KB |
Output is correct |
25 |
Correct |
199 ms |
32596 KB |
Output is correct |
26 |
Correct |
76 ms |
32588 KB |
Output is correct |
27 |
Correct |
180 ms |
53332 KB |
Output is correct |
28 |
Correct |
553 ms |
65140 KB |
Output is correct |
29 |
Correct |
524 ms |
65620 KB |
Output is correct |
30 |
Correct |
186 ms |
53332 KB |
Output is correct |
31 |
Correct |
193 ms |
53324 KB |
Output is correct |
32 |
Correct |
249 ms |
53332 KB |
Output is correct |
33 |
Correct |
425 ms |
52572 KB |
Output is correct |
34 |
Correct |
351 ms |
53432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
724 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
712 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
2 ms |
600 KB |
Output is correct |
38 |
Correct |
2 ms |
600 KB |
Output is correct |
39 |
Correct |
181 ms |
26672 KB |
Output is correct |
40 |
Correct |
200 ms |
26708 KB |
Output is correct |
41 |
Correct |
179 ms |
26848 KB |
Output is correct |
42 |
Correct |
162 ms |
26708 KB |
Output is correct |
43 |
Correct |
130 ms |
27220 KB |
Output is correct |
44 |
Correct |
90 ms |
26460 KB |
Output is correct |
45 |
Correct |
199 ms |
32596 KB |
Output is correct |
46 |
Correct |
76 ms |
32588 KB |
Output is correct |
47 |
Correct |
180 ms |
53332 KB |
Output is correct |
48 |
Correct |
553 ms |
65140 KB |
Output is correct |
49 |
Correct |
524 ms |
65620 KB |
Output is correct |
50 |
Correct |
186 ms |
53332 KB |
Output is correct |
51 |
Correct |
193 ms |
53324 KB |
Output is correct |
52 |
Correct |
249 ms |
53332 KB |
Output is correct |
53 |
Correct |
425 ms |
52572 KB |
Output is correct |
54 |
Correct |
351 ms |
53432 KB |
Output is correct |
55 |
Correct |
19 ms |
3160 KB |
Output is correct |
56 |
Correct |
12 ms |
2904 KB |
Output is correct |
57 |
Correct |
111 ms |
27208 KB |
Output is correct |
58 |
Correct |
47 ms |
26048 KB |
Output is correct |
59 |
Correct |
354 ms |
40532 KB |
Output is correct |
60 |
Correct |
1360 ms |
82856 KB |
Output is correct |
61 |
Correct |
292 ms |
53920 KB |
Output is correct |
62 |
Correct |
280 ms |
53628 KB |
Output is correct |
63 |
Correct |
342 ms |
53584 KB |
Output is correct |
64 |
Correct |
1150 ms |
62800 KB |
Output is correct |
65 |
Correct |
318 ms |
54348 KB |
Output is correct |
66 |
Correct |
971 ms |
65940 KB |
Output is correct |
67 |
Correct |
173 ms |
53128 KB |
Output is correct |
68 |
Correct |
434 ms |
58504 KB |
Output is correct |
69 |
Correct |
455 ms |
58368 KB |
Output is correct |
70 |
Correct |
378 ms |
55636 KB |
Output is correct |