# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
963531 |
2024-04-15T09:23:37 Z |
Amr |
Race (IOI11_race) |
C++17 |
|
622 ms |
45104 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sz size()
typedef long long ll;
ll k,ans =1e18;
const int N = 200002;
vector<pair<ll,ll> > v[N];
ll siz[N], freq[N*5],vis[N];
void build(ll x, ll par)
{
siz[x] = 1;
for(int i = 0; i < v[x].sz; i++)
{
ll nn = v[x][i].F;
if(nn==par||vis[nn]) continue;
build(nn,x);
siz[x]+=siz[nn];
}
}
ll findcn(ll x, ll par, ll m)
{
for(int i = 0; i < v[x].sz; i++)
{
ll nn = v[x][i].F;
if(nn==par||vis[nn]) continue;
if(siz[nn]>m/2) return findcn(nn,x,m);
}
return x;
}
void get(ll x, ll par, ll w , ll d)
{
if(w<=k)
ans=min(ans,freq[k-w]+d);
for(int i = 0 ; i < v[x].sz; i++)
{
ll nn = v[x][i].F;
if(nn==par||vis[nn]) continue;
get(nn,x,w+v[x][i].S,d+1);
}
}
void upd(ll x, ll par, ll w,ll d ,ll tp)
{
if(w<=k&&tp==1)
freq[w] = min(freq[w],d);
else if(w<=k)
freq[w] = 1e18;
for(int i = 0 ; i < v[x].sz; i++)
{
ll nn = v[x][i].F;
if(nn==par||vis[nn]) continue;
upd(nn,x,w+v[x][i].S,d+1,tp);
}
}
void dfs(ll x)
{
build(x,-1);
ll cent = findcn(x, -1, siz[x]/2);
//cout << cent << endl;
vis[cent] = 1;
for(int i = 0; i < v[cent].sz; i++)
{
if(vis[v[cent][i].F]) continue;
get(v[cent][i].F,-1,v[cent][i].S,1);
upd(v[cent][i].F,-1,v[cent][i].S,1,1);
//for(int i = 0; i <= k; i++) cout << freq[i] << " "; cout << ans; cout << endl;
}
ans = min(ans,freq[k]);
for(int i = 0; i < v[cent].sz; i++)
{
if(vis[v[cent][i].F]) continue;
upd(v[cent][i].F,-1,v[cent][i].S,1,1-1);
}
for(int i = 0; i < v[cent].sz; i++)
if(!vis[v[cent][i].F]) dfs(v[cent][i].F);
}
int best_path(int N, int K, int H[][2], int L[])
{
// make the graph
// dfs(ll x) : build , findcn , make it vis , go from childls and make get upd , theen upd2
// build(ll x, ll par), findcn(ll x, ll par)
// get
// update
k = K;
for(int i = 1; i <= k; i++) freq[i] = 1e18;
for(int i = 0; i < N-1; i++)
{
ll x = H[i][0] , y = H[i][1], z = L[i];
v[x].push_back({y,z});
v[y].push_back({x,z});
}
dfs(0);
if(ans>=1e18) return -1;
return ans;
}
Compilation message
race.cpp: In function 'void build(ll, ll)':
race.cpp:15:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i = 0; i < v[x].sz; i++)
| ^
race.cpp: In function 'll findcn(ll, ll, ll)':
race.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0; i < v[x].sz; i++)
| ^
race.cpp: In function 'void get(ll, ll, ll, ll)':
race.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i = 0 ; i < v[x].sz; i++)
| ^
race.cpp: In function 'void upd(ll, ll, ll, ll, ll)':
race.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i = 0 ; i < v[x].sz; i++)
| ^
race.cpp: In function 'void dfs(ll)':
race.cpp:63:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i = 0; i < v[cent].sz; i++)
| ^
race.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i = 0; i < v[cent].sz; i++)
| ^
race.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i = 0; i < v[cent].sz; i++)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
13400 KB |
Output is correct |
2 |
Correct |
2 ms |
13400 KB |
Output is correct |
3 |
Correct |
2 ms |
13484 KB |
Output is correct |
4 |
Correct |
3 ms |
13404 KB |
Output is correct |
5 |
Correct |
3 ms |
13404 KB |
Output is correct |
6 |
Correct |
2 ms |
13404 KB |
Output is correct |
7 |
Correct |
2 ms |
13404 KB |
Output is correct |
8 |
Correct |
2 ms |
13404 KB |
Output is correct |
9 |
Correct |
3 ms |
13404 KB |
Output is correct |
10 |
Correct |
3 ms |
13404 KB |
Output is correct |
11 |
Correct |
2 ms |
13400 KB |
Output is correct |
12 |
Correct |
2 ms |
13404 KB |
Output is correct |
13 |
Correct |
4 ms |
13404 KB |
Output is correct |
14 |
Correct |
3 ms |
13404 KB |
Output is correct |
15 |
Correct |
2 ms |
13400 KB |
Output is correct |
16 |
Correct |
3 ms |
13404 KB |
Output is correct |
17 |
Correct |
2 ms |
13404 KB |
Output is correct |
18 |
Correct |
2 ms |
13404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
13400 KB |
Output is correct |
2 |
Correct |
2 ms |
13400 KB |
Output is correct |
3 |
Correct |
2 ms |
13484 KB |
Output is correct |
4 |
Correct |
3 ms |
13404 KB |
Output is correct |
5 |
Correct |
3 ms |
13404 KB |
Output is correct |
6 |
Correct |
2 ms |
13404 KB |
Output is correct |
7 |
Correct |
2 ms |
13404 KB |
Output is correct |
8 |
Correct |
2 ms |
13404 KB |
Output is correct |
9 |
Correct |
3 ms |
13404 KB |
Output is correct |
10 |
Correct |
3 ms |
13404 KB |
Output is correct |
11 |
Correct |
2 ms |
13400 KB |
Output is correct |
12 |
Correct |
2 ms |
13404 KB |
Output is correct |
13 |
Correct |
4 ms |
13404 KB |
Output is correct |
14 |
Correct |
3 ms |
13404 KB |
Output is correct |
15 |
Correct |
2 ms |
13400 KB |
Output is correct |
16 |
Correct |
3 ms |
13404 KB |
Output is correct |
17 |
Correct |
2 ms |
13404 KB |
Output is correct |
18 |
Correct |
2 ms |
13404 KB |
Output is correct |
19 |
Correct |
2 ms |
13404 KB |
Output is correct |
20 |
Correct |
2 ms |
13404 KB |
Output is correct |
21 |
Correct |
3 ms |
13404 KB |
Output is correct |
22 |
Correct |
4 ms |
19548 KB |
Output is correct |
23 |
Correct |
4 ms |
19548 KB |
Output is correct |
24 |
Correct |
5 ms |
19544 KB |
Output is correct |
25 |
Correct |
4 ms |
19548 KB |
Output is correct |
26 |
Correct |
4 ms |
15688 KB |
Output is correct |
27 |
Correct |
4 ms |
19800 KB |
Output is correct |
28 |
Correct |
3 ms |
15452 KB |
Output is correct |
29 |
Correct |
3 ms |
15452 KB |
Output is correct |
30 |
Correct |
4 ms |
15452 KB |
Output is correct |
31 |
Correct |
4 ms |
19548 KB |
Output is correct |
32 |
Correct |
4 ms |
19548 KB |
Output is correct |
33 |
Correct |
4 ms |
19548 KB |
Output is correct |
34 |
Correct |
4 ms |
17500 KB |
Output is correct |
35 |
Correct |
5 ms |
19704 KB |
Output is correct |
36 |
Correct |
4 ms |
19548 KB |
Output is correct |
37 |
Correct |
4 ms |
19628 KB |
Output is correct |
38 |
Correct |
4 ms |
17500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
13400 KB |
Output is correct |
2 |
Correct |
2 ms |
13400 KB |
Output is correct |
3 |
Correct |
2 ms |
13484 KB |
Output is correct |
4 |
Correct |
3 ms |
13404 KB |
Output is correct |
5 |
Correct |
3 ms |
13404 KB |
Output is correct |
6 |
Correct |
2 ms |
13404 KB |
Output is correct |
7 |
Correct |
2 ms |
13404 KB |
Output is correct |
8 |
Correct |
2 ms |
13404 KB |
Output is correct |
9 |
Correct |
3 ms |
13404 KB |
Output is correct |
10 |
Correct |
3 ms |
13404 KB |
Output is correct |
11 |
Correct |
2 ms |
13400 KB |
Output is correct |
12 |
Correct |
2 ms |
13404 KB |
Output is correct |
13 |
Correct |
4 ms |
13404 KB |
Output is correct |
14 |
Correct |
3 ms |
13404 KB |
Output is correct |
15 |
Correct |
2 ms |
13400 KB |
Output is correct |
16 |
Correct |
3 ms |
13404 KB |
Output is correct |
17 |
Correct |
2 ms |
13404 KB |
Output is correct |
18 |
Correct |
2 ms |
13404 KB |
Output is correct |
19 |
Correct |
155 ms |
20872 KB |
Output is correct |
20 |
Correct |
158 ms |
21840 KB |
Output is correct |
21 |
Correct |
150 ms |
21632 KB |
Output is correct |
22 |
Correct |
118 ms |
22096 KB |
Output is correct |
23 |
Correct |
104 ms |
22688 KB |
Output is correct |
24 |
Correct |
52 ms |
21584 KB |
Output is correct |
25 |
Correct |
167 ms |
27536 KB |
Output is correct |
26 |
Correct |
92 ms |
27428 KB |
Output is correct |
27 |
Correct |
163 ms |
28120 KB |
Output is correct |
28 |
Correct |
450 ms |
39352 KB |
Output is correct |
29 |
Correct |
469 ms |
38992 KB |
Output is correct |
30 |
Correct |
151 ms |
28700 KB |
Output is correct |
31 |
Correct |
173 ms |
28732 KB |
Output is correct |
32 |
Correct |
216 ms |
28608 KB |
Output is correct |
33 |
Correct |
293 ms |
27568 KB |
Output is correct |
34 |
Correct |
292 ms |
27960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
13400 KB |
Output is correct |
2 |
Correct |
2 ms |
13400 KB |
Output is correct |
3 |
Correct |
2 ms |
13484 KB |
Output is correct |
4 |
Correct |
3 ms |
13404 KB |
Output is correct |
5 |
Correct |
3 ms |
13404 KB |
Output is correct |
6 |
Correct |
2 ms |
13404 KB |
Output is correct |
7 |
Correct |
2 ms |
13404 KB |
Output is correct |
8 |
Correct |
2 ms |
13404 KB |
Output is correct |
9 |
Correct |
3 ms |
13404 KB |
Output is correct |
10 |
Correct |
3 ms |
13404 KB |
Output is correct |
11 |
Correct |
2 ms |
13400 KB |
Output is correct |
12 |
Correct |
2 ms |
13404 KB |
Output is correct |
13 |
Correct |
4 ms |
13404 KB |
Output is correct |
14 |
Correct |
3 ms |
13404 KB |
Output is correct |
15 |
Correct |
2 ms |
13400 KB |
Output is correct |
16 |
Correct |
3 ms |
13404 KB |
Output is correct |
17 |
Correct |
2 ms |
13404 KB |
Output is correct |
18 |
Correct |
2 ms |
13404 KB |
Output is correct |
19 |
Correct |
2 ms |
13404 KB |
Output is correct |
20 |
Correct |
2 ms |
13404 KB |
Output is correct |
21 |
Correct |
3 ms |
13404 KB |
Output is correct |
22 |
Correct |
4 ms |
19548 KB |
Output is correct |
23 |
Correct |
4 ms |
19548 KB |
Output is correct |
24 |
Correct |
5 ms |
19544 KB |
Output is correct |
25 |
Correct |
4 ms |
19548 KB |
Output is correct |
26 |
Correct |
4 ms |
15688 KB |
Output is correct |
27 |
Correct |
4 ms |
19800 KB |
Output is correct |
28 |
Correct |
3 ms |
15452 KB |
Output is correct |
29 |
Correct |
3 ms |
15452 KB |
Output is correct |
30 |
Correct |
4 ms |
15452 KB |
Output is correct |
31 |
Correct |
4 ms |
19548 KB |
Output is correct |
32 |
Correct |
4 ms |
19548 KB |
Output is correct |
33 |
Correct |
4 ms |
19548 KB |
Output is correct |
34 |
Correct |
4 ms |
17500 KB |
Output is correct |
35 |
Correct |
5 ms |
19704 KB |
Output is correct |
36 |
Correct |
4 ms |
19548 KB |
Output is correct |
37 |
Correct |
4 ms |
19628 KB |
Output is correct |
38 |
Correct |
4 ms |
17500 KB |
Output is correct |
39 |
Correct |
155 ms |
20872 KB |
Output is correct |
40 |
Correct |
158 ms |
21840 KB |
Output is correct |
41 |
Correct |
150 ms |
21632 KB |
Output is correct |
42 |
Correct |
118 ms |
22096 KB |
Output is correct |
43 |
Correct |
104 ms |
22688 KB |
Output is correct |
44 |
Correct |
52 ms |
21584 KB |
Output is correct |
45 |
Correct |
167 ms |
27536 KB |
Output is correct |
46 |
Correct |
92 ms |
27428 KB |
Output is correct |
47 |
Correct |
163 ms |
28120 KB |
Output is correct |
48 |
Correct |
450 ms |
39352 KB |
Output is correct |
49 |
Correct |
469 ms |
38992 KB |
Output is correct |
50 |
Correct |
151 ms |
28700 KB |
Output is correct |
51 |
Correct |
173 ms |
28732 KB |
Output is correct |
52 |
Correct |
216 ms |
28608 KB |
Output is correct |
53 |
Correct |
293 ms |
27568 KB |
Output is correct |
54 |
Correct |
292 ms |
27960 KB |
Output is correct |
55 |
Correct |
14 ms |
14172 KB |
Output is correct |
56 |
Correct |
13 ms |
13916 KB |
Output is correct |
57 |
Correct |
57 ms |
21292 KB |
Output is correct |
58 |
Correct |
30 ms |
21568 KB |
Output is correct |
59 |
Correct |
92 ms |
29532 KB |
Output is correct |
60 |
Correct |
488 ms |
45104 KB |
Output is correct |
61 |
Correct |
173 ms |
28012 KB |
Output is correct |
62 |
Correct |
186 ms |
34876 KB |
Output is correct |
63 |
Correct |
247 ms |
34752 KB |
Output is correct |
64 |
Correct |
622 ms |
30928 KB |
Output is correct |
65 |
Correct |
327 ms |
29236 KB |
Output is correct |
66 |
Correct |
507 ms |
43076 KB |
Output is correct |
67 |
Correct |
100 ms |
34788 KB |
Output is correct |
68 |
Correct |
282 ms |
34580 KB |
Output is correct |
69 |
Correct |
252 ms |
32080 KB |
Output is correct |
70 |
Correct |
256 ms |
34452 KB |
Output is correct |