#include <bits/stdc++.h>
#define pb push_back
#define task "sequence"
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define fi first
#define se second
using ll = long long;
const long long mod = 1e15+7;
const ll N = 2e5 + 5;
const int base = 350;
using ull = unsigned long long;
using namespace std;
ll n, m, t, k, T, a[N], cnt, ans, u, tong, v, b[N], c[N];
map<ll, ll> mp[N];
vector<pll> kq, adj[N];
void dfs(ll u, ll p, ll hi, ll we)
{
mp[u][we] = hi;
for(pll v : adj[u])
{
if(v.fi == p)continue;
dfs(v.fi, u, hi+1, we+v.se);
if(mp[u].size() < mp[v.fi].size())swap(mp[u], mp[v.fi]);
for(pll x : mp[v.fi])
{
if(mp[u].count(we*2+m-x.fi))ans = min(ans, x.se + mp[u][we*2+m-x.fi] - 2 * hi);
}
for(pll x : mp[v.fi])
{
//if(v.fi == 2)cout << x.fi + v.se<<'\n';
if(!mp[u].count(x.fi) || mp[u][x.fi] > x.se)
{
mp[u][x.fi] = x.se;
if(x.fi== m)ans = min(ans, x.se);
}
}
//cout <<u<<" "<< v.fi<<'\n';
}
//cout << u << '\n';
//for(pll x : mp[u])cout << x.fi <<" "<<x.se<<'\n';
}
int best_path(int ni, int mi, int h[][2], int l[])
{
n = ni;
m = mi;
//cin >> n >> m;
for(int i = 0; i < n-1; i ++)
{
//cin >> a[i] >> b[i];
a[i] = h[i][0];
b[i] = h[i][1];
c[i] = l[i];
}
for(int i = 0; i < n-1; i ++)
{
//cin >> k;
adj[a[i]].pb({b[i], c[i]});
adj[b[i]].pb({a[i], c[i]});
//cout << a[i] <<" "<<b[i] <<" "<<k<<'\n';
}
ans = mod;
dfs(0, 0, 0, 0);
if(ans == mod)ans = -1;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
12 ms |
14592 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
12 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
12 ms |
14592 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
12 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14460 KB |
Output is correct |
19 |
Correct |
11 ms |
14444 KB |
Output is correct |
20 |
Correct |
10 ms |
14444 KB |
Output is correct |
21 |
Correct |
11 ms |
14700 KB |
Output is correct |
22 |
Correct |
12 ms |
14828 KB |
Output is correct |
23 |
Correct |
11 ms |
14828 KB |
Output is correct |
24 |
Correct |
12 ms |
14828 KB |
Output is correct |
25 |
Correct |
12 ms |
14828 KB |
Output is correct |
26 |
Correct |
13 ms |
14828 KB |
Output is correct |
27 |
Correct |
12 ms |
14700 KB |
Output is correct |
28 |
Correct |
11 ms |
14828 KB |
Output is correct |
29 |
Correct |
14 ms |
14828 KB |
Output is correct |
30 |
Correct |
14 ms |
14828 KB |
Output is correct |
31 |
Correct |
11 ms |
14828 KB |
Output is correct |
32 |
Correct |
12 ms |
14828 KB |
Output is correct |
33 |
Correct |
13 ms |
14828 KB |
Output is correct |
34 |
Correct |
11 ms |
14700 KB |
Output is correct |
35 |
Correct |
11 ms |
14700 KB |
Output is correct |
36 |
Correct |
14 ms |
14700 KB |
Output is correct |
37 |
Correct |
13 ms |
14700 KB |
Output is correct |
38 |
Correct |
11 ms |
14700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
12 ms |
14592 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
12 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14460 KB |
Output is correct |
19 |
Correct |
163 ms |
40044 KB |
Output is correct |
20 |
Correct |
205 ms |
40172 KB |
Output is correct |
21 |
Correct |
172 ms |
39788 KB |
Output is correct |
22 |
Correct |
171 ms |
39532 KB |
Output is correct |
23 |
Correct |
270 ms |
52204 KB |
Output is correct |
24 |
Correct |
168 ms |
42220 KB |
Output is correct |
25 |
Correct |
138 ms |
40816 KB |
Output is correct |
26 |
Correct |
83 ms |
49004 KB |
Output is correct |
27 |
Correct |
243 ms |
54252 KB |
Output is correct |
28 |
Correct |
381 ms |
96388 KB |
Output is correct |
29 |
Correct |
361 ms |
94700 KB |
Output is correct |
30 |
Correct |
261 ms |
54252 KB |
Output is correct |
31 |
Correct |
246 ms |
54252 KB |
Output is correct |
32 |
Correct |
320 ms |
54380 KB |
Output is correct |
33 |
Correct |
298 ms |
59244 KB |
Output is correct |
34 |
Correct |
436 ms |
92012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
12 ms |
14592 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
12 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14460 KB |
Output is correct |
19 |
Correct |
11 ms |
14444 KB |
Output is correct |
20 |
Correct |
10 ms |
14444 KB |
Output is correct |
21 |
Correct |
11 ms |
14700 KB |
Output is correct |
22 |
Correct |
12 ms |
14828 KB |
Output is correct |
23 |
Correct |
11 ms |
14828 KB |
Output is correct |
24 |
Correct |
12 ms |
14828 KB |
Output is correct |
25 |
Correct |
12 ms |
14828 KB |
Output is correct |
26 |
Correct |
13 ms |
14828 KB |
Output is correct |
27 |
Correct |
12 ms |
14700 KB |
Output is correct |
28 |
Correct |
11 ms |
14828 KB |
Output is correct |
29 |
Correct |
14 ms |
14828 KB |
Output is correct |
30 |
Correct |
14 ms |
14828 KB |
Output is correct |
31 |
Correct |
11 ms |
14828 KB |
Output is correct |
32 |
Correct |
12 ms |
14828 KB |
Output is correct |
33 |
Correct |
13 ms |
14828 KB |
Output is correct |
34 |
Correct |
11 ms |
14700 KB |
Output is correct |
35 |
Correct |
11 ms |
14700 KB |
Output is correct |
36 |
Correct |
14 ms |
14700 KB |
Output is correct |
37 |
Correct |
13 ms |
14700 KB |
Output is correct |
38 |
Correct |
11 ms |
14700 KB |
Output is correct |
39 |
Correct |
163 ms |
40044 KB |
Output is correct |
40 |
Correct |
205 ms |
40172 KB |
Output is correct |
41 |
Correct |
172 ms |
39788 KB |
Output is correct |
42 |
Correct |
171 ms |
39532 KB |
Output is correct |
43 |
Correct |
270 ms |
52204 KB |
Output is correct |
44 |
Correct |
168 ms |
42220 KB |
Output is correct |
45 |
Correct |
138 ms |
40816 KB |
Output is correct |
46 |
Correct |
83 ms |
49004 KB |
Output is correct |
47 |
Correct |
243 ms |
54252 KB |
Output is correct |
48 |
Correct |
381 ms |
96388 KB |
Output is correct |
49 |
Correct |
361 ms |
94700 KB |
Output is correct |
50 |
Correct |
261 ms |
54252 KB |
Output is correct |
51 |
Correct |
246 ms |
54252 KB |
Output is correct |
52 |
Correct |
320 ms |
54380 KB |
Output is correct |
53 |
Correct |
298 ms |
59244 KB |
Output is correct |
54 |
Correct |
436 ms |
92012 KB |
Output is correct |
55 |
Correct |
27 ms |
18028 KB |
Output is correct |
56 |
Correct |
19 ms |
16620 KB |
Output is correct |
57 |
Correct |
93 ms |
37484 KB |
Output is correct |
58 |
Correct |
70 ms |
30044 KB |
Output is correct |
59 |
Correct |
113 ms |
55276 KB |
Output is correct |
60 |
Correct |
340 ms |
95084 KB |
Output is correct |
61 |
Correct |
292 ms |
57836 KB |
Output is correct |
62 |
Correct |
238 ms |
54252 KB |
Output is correct |
63 |
Correct |
313 ms |
54380 KB |
Output is correct |
64 |
Correct |
571 ms |
109292 KB |
Output is correct |
65 |
Correct |
582 ms |
107504 KB |
Output is correct |
66 |
Correct |
376 ms |
90584 KB |
Output is correct |
67 |
Correct |
233 ms |
47188 KB |
Output is correct |
68 |
Correct |
451 ms |
70636 KB |
Output is correct |
69 |
Correct |
482 ms |
75396 KB |
Output is correct |
70 |
Correct |
429 ms |
68204 KB |
Output is correct |