#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;
/*
*/
struct Info {
map<ll, ll> best;
ll vh, vw;
Info() : vh(0), vw(0) {best[0]=0;}
ll geth(ll val) {
ll tval=val-vw;
return best.count(tval) ? best[tval] + vh : oo;
}
void setmin(ll val, ll h) {
ll tval=val-vw;
if (!best.count(tval) or best[tval] + vh > h) best[tval]=h-vh;
}
};
int best_path(int n, int k, int h[][2], int l[]) {
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]);
}
#warning change ll to ll
ll ans=oo;
vector<Info> infos(n);
auto dfs=[&](auto self, ll a, ll p) -> void{
Info cinfo;
for (auto [b,w] : g[a]) if (b!=p) {
self(self, b, a);
infos[b].vw += w;
infos[b].vh++;
if (sz(infos[b].best) > sz(cinfo.best)) swap(infos[b], cinfo);
ll& vw=infos[b].vw;
ll& vh=infos[b].vh;
for (auto [val, h] : infos[b].best)
ans=min(ans, cinfo.geth(k-(val+vw)) + h+vh);
for (auto [val,h] : infos[b].best)
cinfo.setmin(val+vw, h+vh);
}
swap(cinfo, infos[a]);
};
dfs(dfs,0,-1);
return ans==oo ? -1 : ans;
}
Compilation message
race.cpp:72:3: warning: #warning change ll to ll [-Wcpp]
72 | #warning change ll to ll
| ^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2492 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2492 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2496 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2908 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2788 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
2 ms |
2648 KB |
Output is correct |
33 |
Correct |
2 ms |
2904 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2492 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2496 KB |
Output is correct |
19 |
Correct |
116 ms |
35212 KB |
Output is correct |
20 |
Correct |
91 ms |
35156 KB |
Output is correct |
21 |
Correct |
102 ms |
34900 KB |
Output is correct |
22 |
Correct |
115 ms |
34644 KB |
Output is correct |
23 |
Correct |
149 ms |
47604 KB |
Output is correct |
24 |
Correct |
108 ms |
37460 KB |
Output is correct |
25 |
Correct |
96 ms |
45616 KB |
Output is correct |
26 |
Correct |
65 ms |
63056 KB |
Output is correct |
27 |
Correct |
164 ms |
54612 KB |
Output is correct |
28 |
Correct |
243 ms |
121684 KB |
Output is correct |
29 |
Correct |
238 ms |
118100 KB |
Output is correct |
30 |
Correct |
155 ms |
54440 KB |
Output is correct |
31 |
Correct |
148 ms |
54608 KB |
Output is correct |
32 |
Correct |
202 ms |
54868 KB |
Output is correct |
33 |
Correct |
215 ms |
59732 KB |
Output is correct |
34 |
Correct |
352 ms |
92500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2492 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2496 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2908 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2788 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
2 ms |
2648 KB |
Output is correct |
33 |
Correct |
2 ms |
2904 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
116 ms |
35212 KB |
Output is correct |
40 |
Correct |
91 ms |
35156 KB |
Output is correct |
41 |
Correct |
102 ms |
34900 KB |
Output is correct |
42 |
Correct |
115 ms |
34644 KB |
Output is correct |
43 |
Correct |
149 ms |
47604 KB |
Output is correct |
44 |
Correct |
108 ms |
37460 KB |
Output is correct |
45 |
Correct |
96 ms |
45616 KB |
Output is correct |
46 |
Correct |
65 ms |
63056 KB |
Output is correct |
47 |
Correct |
164 ms |
54612 KB |
Output is correct |
48 |
Correct |
243 ms |
121684 KB |
Output is correct |
49 |
Correct |
238 ms |
118100 KB |
Output is correct |
50 |
Correct |
155 ms |
54440 KB |
Output is correct |
51 |
Correct |
148 ms |
54608 KB |
Output is correct |
52 |
Correct |
202 ms |
54868 KB |
Output is correct |
53 |
Correct |
215 ms |
59732 KB |
Output is correct |
54 |
Correct |
352 ms |
92500 KB |
Output is correct |
55 |
Correct |
12 ms |
6488 KB |
Output is correct |
56 |
Correct |
9 ms |
5212 KB |
Output is correct |
57 |
Correct |
55 ms |
32848 KB |
Output is correct |
58 |
Correct |
41 ms |
25284 KB |
Output is correct |
59 |
Correct |
83 ms |
63056 KB |
Output is correct |
60 |
Correct |
250 ms |
119096 KB |
Output is correct |
61 |
Correct |
191 ms |
58012 KB |
Output is correct |
62 |
Correct |
146 ms |
54480 KB |
Output is correct |
63 |
Correct |
202 ms |
54804 KB |
Output is correct |
64 |
Correct |
439 ms |
109620 KB |
Output is correct |
65 |
Correct |
431 ms |
107852 KB |
Output is correct |
66 |
Correct |
262 ms |
109908 KB |
Output is correct |
67 |
Correct |
138 ms |
47420 KB |
Output is correct |
68 |
Correct |
291 ms |
70744 KB |
Output is correct |
69 |
Correct |
380 ms |
75700 KB |
Output is correct |
70 |
Correct |
319 ms |
67924 KB |
Output is correct |