# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
727888 |
2023-04-21T14:13:33 Z |
onepunchac168 |
Race (IOI11_race) |
C++14 |
|
624 ms |
160480 KB |
// created by Dinh Manh Hung
// onepunchac168
// THPT CHUYEN HA TINH
// HA TINH, VIET NAM
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
//#pragma GCC optimize("O3,unroll-loops,no-stack-protector")
//#pragma GCC target("sse4,avx2,fma")
#define task ""
#define ldb long double
#define pb push_back
#define fi first
#define se second
#define pc pop_back()
#define all(x) begin(x),end(x)
#define uniquev(v) v.resize(unique(all(v))-v.begin())
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define cntbit(v) __builtin_popcountll(v)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((1LL*a*b)/__gcd(a,b))
#define mask(x) (1LL<<(x))
#define readbit(x,i) ((x>>i)&1)
#define ins insert
typedef long long ll;
typedef pair <ll,ll> ii;
typedef pair <ll,ii> iii;
typedef pair <ii,ii> iiii;
ll dx[]= {1,-1,0,0,1,-1,1,-1};
ll dy[]= {0,0,-1,1,1,-1,-1,1};
const ldb PI = acos (-1);
//const ll mod=978846151;
//const ll base=29;
const int maxn=1e6+5;
const int mod=1e9+7;
const char nl = '\n';
ll n,k;
vector <ii> vt[200005];
ll res=1e9+5;
map <ll,ll> *mp[200005];
ll sz[200005];
ll sum[200005];
ll path[200005];
void dfsa(int u,int vv)
{
sz[u]=1;
for (auto v:vt[u])
{
if (v.fi==vv)
{
continue;
}
sum[v.fi]=sum[u]+v.se;
path[v.fi]=path[u]+1;
dfsa(v.fi,u);
sz[u]+=sz[v.fi];
}
}
void dfs(int u,int vv)
{
int bigchild=-1;
for (auto v:vt[u])
{
if (v.fi==vv)
{
continue;
}
if (bigchild==-1||sz[v.fi]>sz[bigchild])
{
bigchild=v.fi;
}
}
if (bigchild!=-1)
{
dfs(bigchild,u);
mp[u]=mp[bigchild];
}
else
{
mp[u]=new map <ll,ll>;
}
ll ss=sum[u]+k;
ll a1=(*mp[u])[ss];
if (a1!=0){
res=min(res,a1-path[u]);
}
ll aa=(*mp[u])[sum[u]];
if (aa==0||path[u]<aa)
{
(*mp[u])[sum[u]]=path[u];
}
for (auto v:vt[u])
{
if (v.fi==vv||v.fi==bigchild)
{
continue;
}
dfs(v.fi,u);
for (auto cnt:*mp[v.fi])
{
if (cnt.se==0)
{
continue;
}
ll aa=k+2*sum[u]-cnt.fi;
ll pp=(*mp[u])[aa];
if (pp!=0)
{
res=min(res,pp+cnt.se-2*path[u]);
}
}
for (auto cnt:*mp[v.fi])
{
if (cnt.se==0)
{
continue;
}
ll aa=(*mp[u])[cnt.fi];
if (aa==0||cnt.se<aa)
{
(*mp[u])[cnt.fi]=cnt.se;
}
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
n=N;
k=K;
for (int i=0;i<n-1;i++)
{
ll aa=H[i][0];
ll bb=H[i][1];
ll w=L[i];
vt[aa].pb({bb,w});
vt[bb].pb({aa,w});
}
sum[0]=0;
path[0]=1;
dfsa(0,-1);
dfs(0,-1);
if (res==1e9+5)
{
return -1;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
4984 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
2 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
4984 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
2 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
5408 KB |
Output is correct |
22 |
Correct |
4 ms |
5588 KB |
Output is correct |
23 |
Correct |
4 ms |
5460 KB |
Output is correct |
24 |
Correct |
5 ms |
5528 KB |
Output is correct |
25 |
Correct |
4 ms |
5460 KB |
Output is correct |
26 |
Correct |
4 ms |
5588 KB |
Output is correct |
27 |
Correct |
4 ms |
5332 KB |
Output is correct |
28 |
Correct |
5 ms |
5460 KB |
Output is correct |
29 |
Correct |
4 ms |
5588 KB |
Output is correct |
30 |
Correct |
5 ms |
5532 KB |
Output is correct |
31 |
Correct |
5 ms |
5460 KB |
Output is correct |
32 |
Correct |
5 ms |
5516 KB |
Output is correct |
33 |
Correct |
5 ms |
5588 KB |
Output is correct |
34 |
Correct |
4 ms |
5332 KB |
Output is correct |
35 |
Correct |
4 ms |
5332 KB |
Output is correct |
36 |
Correct |
4 ms |
5332 KB |
Output is correct |
37 |
Correct |
4 ms |
5272 KB |
Output is correct |
38 |
Correct |
4 ms |
5332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
4984 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
2 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
132 ms |
39276 KB |
Output is correct |
20 |
Correct |
138 ms |
40512 KB |
Output is correct |
21 |
Correct |
131 ms |
40972 KB |
Output is correct |
22 |
Correct |
133 ms |
41296 KB |
Output is correct |
23 |
Correct |
187 ms |
68956 KB |
Output is correct |
24 |
Correct |
145 ms |
54180 KB |
Output is correct |
25 |
Correct |
77 ms |
26260 KB |
Output is correct |
26 |
Correct |
54 ms |
34116 KB |
Output is correct |
27 |
Correct |
204 ms |
57948 KB |
Output is correct |
28 |
Correct |
220 ms |
88620 KB |
Output is correct |
29 |
Correct |
231 ms |
87692 KB |
Output is correct |
30 |
Correct |
197 ms |
57872 KB |
Output is correct |
31 |
Correct |
208 ms |
58000 KB |
Output is correct |
32 |
Correct |
263 ms |
59192 KB |
Output is correct |
33 |
Correct |
201 ms |
44328 KB |
Output is correct |
34 |
Correct |
452 ms |
116172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
4984 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
2 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
5408 KB |
Output is correct |
22 |
Correct |
4 ms |
5588 KB |
Output is correct |
23 |
Correct |
4 ms |
5460 KB |
Output is correct |
24 |
Correct |
5 ms |
5528 KB |
Output is correct |
25 |
Correct |
4 ms |
5460 KB |
Output is correct |
26 |
Correct |
4 ms |
5588 KB |
Output is correct |
27 |
Correct |
4 ms |
5332 KB |
Output is correct |
28 |
Correct |
5 ms |
5460 KB |
Output is correct |
29 |
Correct |
4 ms |
5588 KB |
Output is correct |
30 |
Correct |
5 ms |
5532 KB |
Output is correct |
31 |
Correct |
5 ms |
5460 KB |
Output is correct |
32 |
Correct |
5 ms |
5516 KB |
Output is correct |
33 |
Correct |
5 ms |
5588 KB |
Output is correct |
34 |
Correct |
4 ms |
5332 KB |
Output is correct |
35 |
Correct |
4 ms |
5332 KB |
Output is correct |
36 |
Correct |
4 ms |
5332 KB |
Output is correct |
37 |
Correct |
4 ms |
5272 KB |
Output is correct |
38 |
Correct |
4 ms |
5332 KB |
Output is correct |
39 |
Correct |
132 ms |
39276 KB |
Output is correct |
40 |
Correct |
138 ms |
40512 KB |
Output is correct |
41 |
Correct |
131 ms |
40972 KB |
Output is correct |
42 |
Correct |
133 ms |
41296 KB |
Output is correct |
43 |
Correct |
187 ms |
68956 KB |
Output is correct |
44 |
Correct |
145 ms |
54180 KB |
Output is correct |
45 |
Correct |
77 ms |
26260 KB |
Output is correct |
46 |
Correct |
54 ms |
34116 KB |
Output is correct |
47 |
Correct |
204 ms |
57948 KB |
Output is correct |
48 |
Correct |
220 ms |
88620 KB |
Output is correct |
49 |
Correct |
231 ms |
87692 KB |
Output is correct |
50 |
Correct |
197 ms |
57872 KB |
Output is correct |
51 |
Correct |
208 ms |
58000 KB |
Output is correct |
52 |
Correct |
263 ms |
59192 KB |
Output is correct |
53 |
Correct |
201 ms |
44328 KB |
Output is correct |
54 |
Correct |
452 ms |
116172 KB |
Output is correct |
55 |
Correct |
20 ms |
10416 KB |
Output is correct |
56 |
Correct |
11 ms |
8092 KB |
Output is correct |
57 |
Correct |
82 ms |
41368 KB |
Output is correct |
58 |
Correct |
55 ms |
33820 KB |
Output is correct |
59 |
Correct |
100 ms |
46380 KB |
Output is correct |
60 |
Correct |
281 ms |
87636 KB |
Output is correct |
61 |
Correct |
255 ms |
65548 KB |
Output is correct |
62 |
Correct |
209 ms |
59132 KB |
Output is correct |
63 |
Correct |
258 ms |
59168 KB |
Output is correct |
64 |
Correct |
587 ms |
160292 KB |
Output is correct |
65 |
Correct |
624 ms |
160480 KB |
Output is correct |
66 |
Correct |
301 ms |
85708 KB |
Output is correct |
67 |
Correct |
196 ms |
63868 KB |
Output is correct |
68 |
Correct |
511 ms |
96620 KB |
Output is correct |
69 |
Correct |
510 ms |
97636 KB |
Output is correct |
70 |
Correct |
463 ms |
92648 KB |
Output is correct |