# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
476287 |
2021-09-25T22:07:19 Z |
urosk |
Race (IOI11_race) |
C++14 |
|
1169 ms |
47696 KB |
#include "race.h"
// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x) long long
#define here cerr<<"---------------------------\n"
#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define maxn 200005
vector<pll> g[maxn];
ll n,k,c;
bool vis[maxn];
ll ans = llinf;
ll dfs_siz(ll u,ll par){
ll siz = 1;
for(pll p : g[u]){
ll v = p.fi;
if(vis[v]||v==par) continue;
siz+=dfs_siz(v,u);
}
return siz;
}
ll decomp(ll u,ll par,ll m){
ll siz = 1;
bool ok = 1;
for(pll p : g[u]){
ll v = p.fi;
if(vis[v]||v==par) continue;
ll e = decomp(v,u,m);
if(e>m/2) ok = 0;
siz+=e;
}
if(siz<m/2) ok = 0;
if(ok) c = u;
return siz;
}
void dfs(ll u,ll par,ll len,ll j){
if(len==k) ans = min(ans,j);
if(len>=k) return;
for(pll p : g[u]){
ll v = p.fi;
ll w = p.sc;
if(vis[v]||v==par) continue;
dfs(v,u,len+w,j+1);
}
}
map<ll,ll> cnt;
vector<pll> tmp;
void calc(ll u,ll par,ll len,ll j){
if(len>k) return;
if(cnt.find(k-len)!=cnt.end()) ans = min(ans,cnt[k-len]+j);
tmp.pb({len,j});
for(pll p : g[u]){
ll v = p.fi;
ll w = p.sc;
if(vis[v]||v==par) continue;
calc(v,u,len+w,j+1);
}
}
void solve(ll u){
decomp(u,u,dfs_siz(u,u));
//cerr<<u<< " "<<c<<endl;
dfs(c,c,0,0);
vis[c] = 1;
cnt.clear();
for(pll p : g[c]){
ll v = p.fi;
ll w = p.sc;
if(vis[v]) continue;
calc(v,v,w,1);
while(!tmp.empty()){
ll id = tmp.back().fi;
ll len = tmp.back().sc;
tmp.popb();
if(cnt.find(id)==cnt.end()) cnt[id] = len;
else cnt[id] = min(cnt[id],len);
}
}
ll r = c;
for(pll p : g[r]){
ll v = p.fi;
if(vis[v]) continue;
solve(v);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
n = N;
k = K;
for(ll i = 1;i<=n-1;i++){
ll x = H[i-1][0],y = H[i-1][1],w = L[i-1];
x++;
y++;
g[x].pb({y,w});
g[y].pb({x,w});
}
solve(1);
if(ans==llinf) ans = -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
5068 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
5020 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
5004 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4960 KB |
Output is correct |
13 |
Correct |
3 ms |
5000 KB |
Output is correct |
14 |
Correct |
3 ms |
5000 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4916 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
5068 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
5020 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
5004 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4960 KB |
Output is correct |
13 |
Correct |
3 ms |
5000 KB |
Output is correct |
14 |
Correct |
3 ms |
5000 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4916 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
5 ms |
5068 KB |
Output is correct |
22 |
Correct |
3 ms |
5068 KB |
Output is correct |
23 |
Correct |
4 ms |
5068 KB |
Output is correct |
24 |
Correct |
4 ms |
5068 KB |
Output is correct |
25 |
Correct |
4 ms |
5068 KB |
Output is correct |
26 |
Correct |
4 ms |
5012 KB |
Output is correct |
27 |
Correct |
4 ms |
5068 KB |
Output is correct |
28 |
Correct |
5 ms |
5068 KB |
Output is correct |
29 |
Correct |
4 ms |
5068 KB |
Output is correct |
30 |
Correct |
5 ms |
5068 KB |
Output is correct |
31 |
Correct |
4 ms |
5068 KB |
Output is correct |
32 |
Correct |
5 ms |
5068 KB |
Output is correct |
33 |
Correct |
5 ms |
5068 KB |
Output is correct |
34 |
Correct |
4 ms |
5068 KB |
Output is correct |
35 |
Correct |
4 ms |
5068 KB |
Output is correct |
36 |
Correct |
5 ms |
5068 KB |
Output is correct |
37 |
Correct |
5 ms |
5068 KB |
Output is correct |
38 |
Correct |
5 ms |
5140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
5068 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
5020 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
5004 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4960 KB |
Output is correct |
13 |
Correct |
3 ms |
5000 KB |
Output is correct |
14 |
Correct |
3 ms |
5000 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4916 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
244 ms |
12956 KB |
Output is correct |
20 |
Correct |
276 ms |
12916 KB |
Output is correct |
21 |
Correct |
270 ms |
13260 KB |
Output is correct |
22 |
Correct |
280 ms |
13380 KB |
Output is correct |
23 |
Correct |
102 ms |
13104 KB |
Output is correct |
24 |
Correct |
85 ms |
12328 KB |
Output is correct |
25 |
Correct |
179 ms |
16408 KB |
Output is correct |
26 |
Correct |
137 ms |
21088 KB |
Output is correct |
27 |
Correct |
273 ms |
21204 KB |
Output is correct |
28 |
Correct |
365 ms |
35536 KB |
Output is correct |
29 |
Correct |
350 ms |
34464 KB |
Output is correct |
30 |
Correct |
288 ms |
21196 KB |
Output is correct |
31 |
Correct |
254 ms |
21260 KB |
Output is correct |
32 |
Correct |
334 ms |
21272 KB |
Output is correct |
33 |
Correct |
406 ms |
20088 KB |
Output is correct |
34 |
Correct |
252 ms |
20912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
5068 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
5020 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
5004 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4960 KB |
Output is correct |
13 |
Correct |
3 ms |
5000 KB |
Output is correct |
14 |
Correct |
3 ms |
5000 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4916 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
5 ms |
5068 KB |
Output is correct |
22 |
Correct |
3 ms |
5068 KB |
Output is correct |
23 |
Correct |
4 ms |
5068 KB |
Output is correct |
24 |
Correct |
4 ms |
5068 KB |
Output is correct |
25 |
Correct |
4 ms |
5068 KB |
Output is correct |
26 |
Correct |
4 ms |
5012 KB |
Output is correct |
27 |
Correct |
4 ms |
5068 KB |
Output is correct |
28 |
Correct |
5 ms |
5068 KB |
Output is correct |
29 |
Correct |
4 ms |
5068 KB |
Output is correct |
30 |
Correct |
5 ms |
5068 KB |
Output is correct |
31 |
Correct |
4 ms |
5068 KB |
Output is correct |
32 |
Correct |
5 ms |
5068 KB |
Output is correct |
33 |
Correct |
5 ms |
5068 KB |
Output is correct |
34 |
Correct |
4 ms |
5068 KB |
Output is correct |
35 |
Correct |
4 ms |
5068 KB |
Output is correct |
36 |
Correct |
5 ms |
5068 KB |
Output is correct |
37 |
Correct |
5 ms |
5068 KB |
Output is correct |
38 |
Correct |
5 ms |
5140 KB |
Output is correct |
39 |
Correct |
244 ms |
12956 KB |
Output is correct |
40 |
Correct |
276 ms |
12916 KB |
Output is correct |
41 |
Correct |
270 ms |
13260 KB |
Output is correct |
42 |
Correct |
280 ms |
13380 KB |
Output is correct |
43 |
Correct |
102 ms |
13104 KB |
Output is correct |
44 |
Correct |
85 ms |
12328 KB |
Output is correct |
45 |
Correct |
179 ms |
16408 KB |
Output is correct |
46 |
Correct |
137 ms |
21088 KB |
Output is correct |
47 |
Correct |
273 ms |
21204 KB |
Output is correct |
48 |
Correct |
365 ms |
35536 KB |
Output is correct |
49 |
Correct |
350 ms |
34464 KB |
Output is correct |
50 |
Correct |
288 ms |
21196 KB |
Output is correct |
51 |
Correct |
254 ms |
21260 KB |
Output is correct |
52 |
Correct |
334 ms |
21272 KB |
Output is correct |
53 |
Correct |
406 ms |
20088 KB |
Output is correct |
54 |
Correct |
252 ms |
20912 KB |
Output is correct |
55 |
Correct |
30 ms |
5892 KB |
Output is correct |
56 |
Correct |
24 ms |
5960 KB |
Output is correct |
57 |
Correct |
161 ms |
14036 KB |
Output is correct |
58 |
Correct |
49 ms |
12028 KB |
Output is correct |
59 |
Correct |
330 ms |
25680 KB |
Output is correct |
60 |
Correct |
1081 ms |
47696 KB |
Output is correct |
61 |
Correct |
340 ms |
21612 KB |
Output is correct |
62 |
Correct |
367 ms |
21464 KB |
Output is correct |
63 |
Correct |
452 ms |
21572 KB |
Output is correct |
64 |
Correct |
1169 ms |
28712 KB |
Output is correct |
65 |
Correct |
293 ms |
21572 KB |
Output is correct |
66 |
Correct |
665 ms |
32348 KB |
Output is correct |
67 |
Correct |
150 ms |
20352 KB |
Output is correct |
68 |
Correct |
491 ms |
26268 KB |
Output is correct |
69 |
Correct |
483 ms |
25920 KB |
Output is correct |
70 |
Correct |
439 ms |
25268 KB |
Output is correct |