# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
986313 |
2024-05-20T09:55:56 Z |
Pyqe |
Race (IOI11_race) |
C++17 |
|
367 ms |
120144 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fr first
#define sc second
long long d,dsu[200069],cc[200069],lz[200069][2],z,inf=1e18;
vector<pair<long long,long long>> al[200069];
bitset<200069> vtd;
multiset<pair<long long,long long>> ms[200069];
multiset<pair<long long,long long>>::iterator it,it2;
long long fd(long long x)
{
if(dsu[x]!=x)
{
dsu[x]=fd(dsu[x]);
}
return dsu[x];
}
void jo(long long x,long long y)
{
long long k,w;
x=fd(x);
y=fd(y);
if(cc[x]<cc[y])
{
swap(x,y);
}
for(it=ms[y].begin();it!=ms[y].end();it++)
{
k=it->fr+lz[y][1];
w=it->sc+lz[y][0];
it2=ms[x].lower_bound({d-k-lz[x][1],-inf});
if(it2!=ms[x].end()&&it2->fr+lz[x][1]==d-k)
{
z=min(z,w+it2->sc+lz[x][0]);
}
}
for(it=ms[y].begin();it!=ms[y].end();it++)
{
k=it->fr+lz[y][1];
w=it->sc+lz[y][0];
ms[x].insert({k-lz[x][1],w-lz[x][0]});
}
dsu[y]=x;
cc[x]+=cc[y];
}
void dfs(long long x)
{
long long i,sz=al[x].size(),l,w;
vtd[x]=1;
dsu[x]=x;
cc[x]=1;
ms[x].insert({0,0});
for(i=0;i<sz;i++)
{
l=al[x][i].fr;
w=al[x][i].sc;
if(!vtd[l])
{
dfs(l);
lz[fd(l)][0]++;
lz[fd(l)][1]+=w;
jo(x,l);
}
}
}
int best_path(int n,int od,int ed[][2],int wg[])
{
long long i,k,l;
d=od;
for(i=0;i<n-1;i++)
{
k=ed[i][0];
l=ed[i][1];
al[k].push_back({l,wg[i]});
al[l].push_back({k,wg[i]});
}
z=inf;
dfs(0);
if(z==inf)
{
z=-1;
}
return z;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
20824 KB |
Output is correct |
2 |
Correct |
4 ms |
20828 KB |
Output is correct |
3 |
Correct |
4 ms |
20828 KB |
Output is correct |
4 |
Correct |
4 ms |
20828 KB |
Output is correct |
5 |
Correct |
4 ms |
20828 KB |
Output is correct |
6 |
Correct |
4 ms |
20828 KB |
Output is correct |
7 |
Correct |
4 ms |
20828 KB |
Output is correct |
8 |
Correct |
4 ms |
20828 KB |
Output is correct |
9 |
Correct |
4 ms |
21080 KB |
Output is correct |
10 |
Correct |
4 ms |
20828 KB |
Output is correct |
11 |
Correct |
4 ms |
20824 KB |
Output is correct |
12 |
Correct |
4 ms |
20828 KB |
Output is correct |
13 |
Correct |
4 ms |
20824 KB |
Output is correct |
14 |
Correct |
4 ms |
20828 KB |
Output is correct |
15 |
Correct |
4 ms |
20824 KB |
Output is correct |
16 |
Correct |
4 ms |
20828 KB |
Output is correct |
17 |
Correct |
4 ms |
20828 KB |
Output is correct |
18 |
Correct |
4 ms |
20828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
20824 KB |
Output is correct |
2 |
Correct |
4 ms |
20828 KB |
Output is correct |
3 |
Correct |
4 ms |
20828 KB |
Output is correct |
4 |
Correct |
4 ms |
20828 KB |
Output is correct |
5 |
Correct |
4 ms |
20828 KB |
Output is correct |
6 |
Correct |
4 ms |
20828 KB |
Output is correct |
7 |
Correct |
4 ms |
20828 KB |
Output is correct |
8 |
Correct |
4 ms |
20828 KB |
Output is correct |
9 |
Correct |
4 ms |
21080 KB |
Output is correct |
10 |
Correct |
4 ms |
20828 KB |
Output is correct |
11 |
Correct |
4 ms |
20824 KB |
Output is correct |
12 |
Correct |
4 ms |
20828 KB |
Output is correct |
13 |
Correct |
4 ms |
20824 KB |
Output is correct |
14 |
Correct |
4 ms |
20828 KB |
Output is correct |
15 |
Correct |
4 ms |
20824 KB |
Output is correct |
16 |
Correct |
4 ms |
20828 KB |
Output is correct |
17 |
Correct |
4 ms |
20828 KB |
Output is correct |
18 |
Correct |
4 ms |
20828 KB |
Output is correct |
19 |
Correct |
4 ms |
20828 KB |
Output is correct |
20 |
Correct |
4 ms |
20824 KB |
Output is correct |
21 |
Correct |
5 ms |
21080 KB |
Output is correct |
22 |
Correct |
5 ms |
21184 KB |
Output is correct |
23 |
Correct |
5 ms |
21220 KB |
Output is correct |
24 |
Correct |
5 ms |
21080 KB |
Output is correct |
25 |
Correct |
5 ms |
21084 KB |
Output is correct |
26 |
Correct |
5 ms |
21036 KB |
Output is correct |
27 |
Correct |
5 ms |
21080 KB |
Output is correct |
28 |
Correct |
5 ms |
21084 KB |
Output is correct |
29 |
Correct |
5 ms |
21196 KB |
Output is correct |
30 |
Correct |
7 ms |
21280 KB |
Output is correct |
31 |
Correct |
5 ms |
21084 KB |
Output is correct |
32 |
Correct |
6 ms |
21084 KB |
Output is correct |
33 |
Correct |
5 ms |
21084 KB |
Output is correct |
34 |
Correct |
5 ms |
21084 KB |
Output is correct |
35 |
Correct |
6 ms |
21084 KB |
Output is correct |
36 |
Correct |
5 ms |
21200 KB |
Output is correct |
37 |
Correct |
5 ms |
21084 KB |
Output is correct |
38 |
Correct |
5 ms |
21084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
20824 KB |
Output is correct |
2 |
Correct |
4 ms |
20828 KB |
Output is correct |
3 |
Correct |
4 ms |
20828 KB |
Output is correct |
4 |
Correct |
4 ms |
20828 KB |
Output is correct |
5 |
Correct |
4 ms |
20828 KB |
Output is correct |
6 |
Correct |
4 ms |
20828 KB |
Output is correct |
7 |
Correct |
4 ms |
20828 KB |
Output is correct |
8 |
Correct |
4 ms |
20828 KB |
Output is correct |
9 |
Correct |
4 ms |
21080 KB |
Output is correct |
10 |
Correct |
4 ms |
20828 KB |
Output is correct |
11 |
Correct |
4 ms |
20824 KB |
Output is correct |
12 |
Correct |
4 ms |
20828 KB |
Output is correct |
13 |
Correct |
4 ms |
20824 KB |
Output is correct |
14 |
Correct |
4 ms |
20828 KB |
Output is correct |
15 |
Correct |
4 ms |
20824 KB |
Output is correct |
16 |
Correct |
4 ms |
20828 KB |
Output is correct |
17 |
Correct |
4 ms |
20828 KB |
Output is correct |
18 |
Correct |
4 ms |
20828 KB |
Output is correct |
19 |
Correct |
166 ms |
71632 KB |
Output is correct |
20 |
Correct |
173 ms |
71900 KB |
Output is correct |
21 |
Correct |
175 ms |
72180 KB |
Output is correct |
22 |
Correct |
161 ms |
67408 KB |
Output is correct |
23 |
Correct |
196 ms |
84816 KB |
Output is correct |
24 |
Correct |
150 ms |
68432 KB |
Output is correct |
25 |
Correct |
107 ms |
52964 KB |
Output is correct |
26 |
Correct |
62 ms |
54584 KB |
Output is correct |
27 |
Correct |
236 ms |
76056 KB |
Output is correct |
28 |
Correct |
206 ms |
84520 KB |
Output is correct |
29 |
Correct |
202 ms |
82136 KB |
Output is correct |
30 |
Correct |
225 ms |
76620 KB |
Output is correct |
31 |
Correct |
229 ms |
76772 KB |
Output is correct |
32 |
Correct |
316 ms |
76772 KB |
Output is correct |
33 |
Correct |
270 ms |
97108 KB |
Output is correct |
34 |
Correct |
259 ms |
95248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
20824 KB |
Output is correct |
2 |
Correct |
4 ms |
20828 KB |
Output is correct |
3 |
Correct |
4 ms |
20828 KB |
Output is correct |
4 |
Correct |
4 ms |
20828 KB |
Output is correct |
5 |
Correct |
4 ms |
20828 KB |
Output is correct |
6 |
Correct |
4 ms |
20828 KB |
Output is correct |
7 |
Correct |
4 ms |
20828 KB |
Output is correct |
8 |
Correct |
4 ms |
20828 KB |
Output is correct |
9 |
Correct |
4 ms |
21080 KB |
Output is correct |
10 |
Correct |
4 ms |
20828 KB |
Output is correct |
11 |
Correct |
4 ms |
20824 KB |
Output is correct |
12 |
Correct |
4 ms |
20828 KB |
Output is correct |
13 |
Correct |
4 ms |
20824 KB |
Output is correct |
14 |
Correct |
4 ms |
20828 KB |
Output is correct |
15 |
Correct |
4 ms |
20824 KB |
Output is correct |
16 |
Correct |
4 ms |
20828 KB |
Output is correct |
17 |
Correct |
4 ms |
20828 KB |
Output is correct |
18 |
Correct |
4 ms |
20828 KB |
Output is correct |
19 |
Correct |
4 ms |
20828 KB |
Output is correct |
20 |
Correct |
4 ms |
20824 KB |
Output is correct |
21 |
Correct |
5 ms |
21080 KB |
Output is correct |
22 |
Correct |
5 ms |
21184 KB |
Output is correct |
23 |
Correct |
5 ms |
21220 KB |
Output is correct |
24 |
Correct |
5 ms |
21080 KB |
Output is correct |
25 |
Correct |
5 ms |
21084 KB |
Output is correct |
26 |
Correct |
5 ms |
21036 KB |
Output is correct |
27 |
Correct |
5 ms |
21080 KB |
Output is correct |
28 |
Correct |
5 ms |
21084 KB |
Output is correct |
29 |
Correct |
5 ms |
21196 KB |
Output is correct |
30 |
Correct |
7 ms |
21280 KB |
Output is correct |
31 |
Correct |
5 ms |
21084 KB |
Output is correct |
32 |
Correct |
6 ms |
21084 KB |
Output is correct |
33 |
Correct |
5 ms |
21084 KB |
Output is correct |
34 |
Correct |
5 ms |
21084 KB |
Output is correct |
35 |
Correct |
6 ms |
21084 KB |
Output is correct |
36 |
Correct |
5 ms |
21200 KB |
Output is correct |
37 |
Correct |
5 ms |
21084 KB |
Output is correct |
38 |
Correct |
5 ms |
21084 KB |
Output is correct |
39 |
Correct |
166 ms |
71632 KB |
Output is correct |
40 |
Correct |
173 ms |
71900 KB |
Output is correct |
41 |
Correct |
175 ms |
72180 KB |
Output is correct |
42 |
Correct |
161 ms |
67408 KB |
Output is correct |
43 |
Correct |
196 ms |
84816 KB |
Output is correct |
44 |
Correct |
150 ms |
68432 KB |
Output is correct |
45 |
Correct |
107 ms |
52964 KB |
Output is correct |
46 |
Correct |
62 ms |
54584 KB |
Output is correct |
47 |
Correct |
236 ms |
76056 KB |
Output is correct |
48 |
Correct |
206 ms |
84520 KB |
Output is correct |
49 |
Correct |
202 ms |
82136 KB |
Output is correct |
50 |
Correct |
225 ms |
76620 KB |
Output is correct |
51 |
Correct |
229 ms |
76772 KB |
Output is correct |
52 |
Correct |
316 ms |
76772 KB |
Output is correct |
53 |
Correct |
270 ms |
97108 KB |
Output is correct |
54 |
Correct |
259 ms |
95248 KB |
Output is correct |
55 |
Correct |
14 ms |
24408 KB |
Output is correct |
56 |
Correct |
15 ms |
24844 KB |
Output is correct |
57 |
Correct |
175 ms |
85548 KB |
Output is correct |
58 |
Correct |
76 ms |
43936 KB |
Output is correct |
59 |
Correct |
62 ms |
54868 KB |
Output is correct |
60 |
Correct |
199 ms |
84352 KB |
Output is correct |
61 |
Correct |
231 ms |
76112 KB |
Output is correct |
62 |
Correct |
224 ms |
76624 KB |
Output is correct |
63 |
Correct |
300 ms |
76660 KB |
Output is correct |
64 |
Correct |
367 ms |
120144 KB |
Output is correct |
65 |
Correct |
344 ms |
111900 KB |
Output is correct |
66 |
Correct |
229 ms |
80648 KB |
Output is correct |
67 |
Correct |
251 ms |
65232 KB |
Output is correct |
68 |
Correct |
282 ms |
76208 KB |
Output is correct |
69 |
Correct |
317 ms |
79536 KB |
Output is correct |
70 |
Correct |
266 ms |
74320 KB |
Output is correct |