# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
531096 |
2022-02-27T18:08:33 Z |
SavicS |
Race (IOI11_race) |
C++17 |
|
364 ms |
38680 KB |
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)
#define trav(a,x) for (auto& a : x)
#define sz(a) (int)(a).size()
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
const int mod = 1000000007;
const int inf = 1e9 + 5;
const int mxN = 200005;
int n, k;
vector<pii> g[mxN];
int cnt[mxN];
bool visited[mxN];
void dfs_cnt(int v, int p){
cnt[v] = 1;
for(auto c : g[v]){
if(!visited[c.fi] && c.fi != p){
dfs_cnt(c.fi, v);
cnt[v] += cnt[c.fi];
}
}
}
int centroid(int v, int p, int vel){
for(auto c : g[v]){
if(c.fi == p || visited[c.fi])continue;
if(cnt[c.fi] > vel / 2)return centroid(c.fi, v, vel);
}
return v;
}
const int M = 1e6;
int kol[M + 5];
int rez = inf;
vector<pii> cuvaj;
void dfs(int v, int p, int A, int d){
if(A > k)return;
rez = min(rez, d + kol[k - A]);
cuvaj.pb({A, d});
for(auto c : g[v]){
int u = c.fi;
int w = c.se;
if(u != p && !visited[u]){
dfs(u, v, A + w, d + 1);
}
}
}
void decmopose(int v, int p){
dfs_cnt(v, -1); int cen = centroid(v, -1, cnt[v]);
visited[cen] = 1;
kol[0] = 0; vector<int> brisi;
for(auto c : g[cen]){
int u = c.fi;
int w = c.se;
if(u != p && !visited[u]){
cuvaj.clear(); dfs(u, cen, w, 1);
for(auto c : cuvaj){
if(kol[c.fi] == inf)brisi.pb(c.fi);
kol[c.fi] = min(kol[c.fi], c.se);
}
}
}
for(auto c : brisi)kol[c] = inf;
for(auto c : g[cen]){
if(c.fi != p && !visited[c.fi])decmopose(c.fi, cen);
}
}
int best_path(int N, int K, int H[][2], int L[]){
n = N; k = K;
ff(i,0,n - 2){
int u = H[i][0] + 1;
int v = H[i][1] + 1;
int w = L[i];
g[u].pb({v, w});
g[v].pb({u, w});
}
ff(i,0,M)kol[i] = inf;
decmopose(1, -1);
return (rez == inf ? -1 : rez);
}
// int main() {
// cin.tie(0)->sync_with_stdio(0);
// cin >> n >> k;
// int H[n][2], L[n];
// ff(i,0,n - 2){
// cin >> H[i][0] >> H[i][1] >> L[i];
// H[i][0] -= 1; H[i][1] -= 1;
// }
// cout << best_path(n, k, H, L) << '\n';
// return 0;
// }
/*
9 57
2 1 50
3 1 11
4 2 4
5 2 53
6 2 64
7 4 7
8 6 10
9 2 55
6 7
0 1 1
0 2 1
1 4 3
1 3 8
4 5 2
4 3
0 1 1
1 2 2
1 3 4
3 3
0 1 1
1 2 1
11 12
0 1 3
0 2 4
2 3 5
3 4 4
4 5 6
0 6 3
6 7 2
6 8 5
8 9 6
8 10 7
// probati bojenje sahovski
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8900 KB |
Output is correct |
2 |
Correct |
5 ms |
8848 KB |
Output is correct |
3 |
Correct |
5 ms |
8852 KB |
Output is correct |
4 |
Correct |
5 ms |
8908 KB |
Output is correct |
5 |
Correct |
5 ms |
8852 KB |
Output is correct |
6 |
Correct |
5 ms |
8908 KB |
Output is correct |
7 |
Correct |
5 ms |
8908 KB |
Output is correct |
8 |
Correct |
6 ms |
8856 KB |
Output is correct |
9 |
Correct |
5 ms |
8908 KB |
Output is correct |
10 |
Correct |
5 ms |
8908 KB |
Output is correct |
11 |
Correct |
6 ms |
8848 KB |
Output is correct |
12 |
Correct |
5 ms |
8908 KB |
Output is correct |
13 |
Correct |
5 ms |
8908 KB |
Output is correct |
14 |
Correct |
4 ms |
8848 KB |
Output is correct |
15 |
Correct |
5 ms |
8852 KB |
Output is correct |
16 |
Correct |
4 ms |
8908 KB |
Output is correct |
17 |
Correct |
5 ms |
8856 KB |
Output is correct |
18 |
Correct |
5 ms |
8908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8900 KB |
Output is correct |
2 |
Correct |
5 ms |
8848 KB |
Output is correct |
3 |
Correct |
5 ms |
8852 KB |
Output is correct |
4 |
Correct |
5 ms |
8908 KB |
Output is correct |
5 |
Correct |
5 ms |
8852 KB |
Output is correct |
6 |
Correct |
5 ms |
8908 KB |
Output is correct |
7 |
Correct |
5 ms |
8908 KB |
Output is correct |
8 |
Correct |
6 ms |
8856 KB |
Output is correct |
9 |
Correct |
5 ms |
8908 KB |
Output is correct |
10 |
Correct |
5 ms |
8908 KB |
Output is correct |
11 |
Correct |
6 ms |
8848 KB |
Output is correct |
12 |
Correct |
5 ms |
8908 KB |
Output is correct |
13 |
Correct |
5 ms |
8908 KB |
Output is correct |
14 |
Correct |
4 ms |
8848 KB |
Output is correct |
15 |
Correct |
5 ms |
8852 KB |
Output is correct |
16 |
Correct |
4 ms |
8908 KB |
Output is correct |
17 |
Correct |
5 ms |
8856 KB |
Output is correct |
18 |
Correct |
5 ms |
8908 KB |
Output is correct |
19 |
Correct |
5 ms |
8832 KB |
Output is correct |
20 |
Correct |
6 ms |
8844 KB |
Output is correct |
21 |
Correct |
7 ms |
8908 KB |
Output is correct |
22 |
Correct |
7 ms |
8948 KB |
Output is correct |
23 |
Correct |
8 ms |
8908 KB |
Output is correct |
24 |
Correct |
5 ms |
9000 KB |
Output is correct |
25 |
Correct |
5 ms |
8992 KB |
Output is correct |
26 |
Correct |
5 ms |
8908 KB |
Output is correct |
27 |
Correct |
6 ms |
8980 KB |
Output is correct |
28 |
Correct |
5 ms |
8908 KB |
Output is correct |
29 |
Correct |
5 ms |
8908 KB |
Output is correct |
30 |
Correct |
5 ms |
8996 KB |
Output is correct |
31 |
Correct |
7 ms |
8988 KB |
Output is correct |
32 |
Correct |
5 ms |
8908 KB |
Output is correct |
33 |
Correct |
5 ms |
8908 KB |
Output is correct |
34 |
Correct |
5 ms |
8908 KB |
Output is correct |
35 |
Correct |
5 ms |
8908 KB |
Output is correct |
36 |
Correct |
7 ms |
8988 KB |
Output is correct |
37 |
Correct |
5 ms |
8908 KB |
Output is correct |
38 |
Correct |
6 ms |
8908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8900 KB |
Output is correct |
2 |
Correct |
5 ms |
8848 KB |
Output is correct |
3 |
Correct |
5 ms |
8852 KB |
Output is correct |
4 |
Correct |
5 ms |
8908 KB |
Output is correct |
5 |
Correct |
5 ms |
8852 KB |
Output is correct |
6 |
Correct |
5 ms |
8908 KB |
Output is correct |
7 |
Correct |
5 ms |
8908 KB |
Output is correct |
8 |
Correct |
6 ms |
8856 KB |
Output is correct |
9 |
Correct |
5 ms |
8908 KB |
Output is correct |
10 |
Correct |
5 ms |
8908 KB |
Output is correct |
11 |
Correct |
6 ms |
8848 KB |
Output is correct |
12 |
Correct |
5 ms |
8908 KB |
Output is correct |
13 |
Correct |
5 ms |
8908 KB |
Output is correct |
14 |
Correct |
4 ms |
8848 KB |
Output is correct |
15 |
Correct |
5 ms |
8852 KB |
Output is correct |
16 |
Correct |
4 ms |
8908 KB |
Output is correct |
17 |
Correct |
5 ms |
8856 KB |
Output is correct |
18 |
Correct |
5 ms |
8908 KB |
Output is correct |
19 |
Correct |
99 ms |
14436 KB |
Output is correct |
20 |
Correct |
112 ms |
14356 KB |
Output is correct |
21 |
Correct |
140 ms |
14708 KB |
Output is correct |
22 |
Correct |
99 ms |
14784 KB |
Output is correct |
23 |
Correct |
72 ms |
14532 KB |
Output is correct |
24 |
Correct |
53 ms |
14492 KB |
Output is correct |
25 |
Correct |
121 ms |
17988 KB |
Output is correct |
26 |
Correct |
88 ms |
22420 KB |
Output is correct |
27 |
Correct |
151 ms |
19836 KB |
Output is correct |
28 |
Correct |
250 ms |
34140 KB |
Output is correct |
29 |
Correct |
250 ms |
33112 KB |
Output is correct |
30 |
Correct |
169 ms |
19888 KB |
Output is correct |
31 |
Correct |
152 ms |
19892 KB |
Output is correct |
32 |
Correct |
197 ms |
19948 KB |
Output is correct |
33 |
Correct |
254 ms |
18716 KB |
Output is correct |
34 |
Correct |
156 ms |
18756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8900 KB |
Output is correct |
2 |
Correct |
5 ms |
8848 KB |
Output is correct |
3 |
Correct |
5 ms |
8852 KB |
Output is correct |
4 |
Correct |
5 ms |
8908 KB |
Output is correct |
5 |
Correct |
5 ms |
8852 KB |
Output is correct |
6 |
Correct |
5 ms |
8908 KB |
Output is correct |
7 |
Correct |
5 ms |
8908 KB |
Output is correct |
8 |
Correct |
6 ms |
8856 KB |
Output is correct |
9 |
Correct |
5 ms |
8908 KB |
Output is correct |
10 |
Correct |
5 ms |
8908 KB |
Output is correct |
11 |
Correct |
6 ms |
8848 KB |
Output is correct |
12 |
Correct |
5 ms |
8908 KB |
Output is correct |
13 |
Correct |
5 ms |
8908 KB |
Output is correct |
14 |
Correct |
4 ms |
8848 KB |
Output is correct |
15 |
Correct |
5 ms |
8852 KB |
Output is correct |
16 |
Correct |
4 ms |
8908 KB |
Output is correct |
17 |
Correct |
5 ms |
8856 KB |
Output is correct |
18 |
Correct |
5 ms |
8908 KB |
Output is correct |
19 |
Correct |
5 ms |
8832 KB |
Output is correct |
20 |
Correct |
6 ms |
8844 KB |
Output is correct |
21 |
Correct |
7 ms |
8908 KB |
Output is correct |
22 |
Correct |
7 ms |
8948 KB |
Output is correct |
23 |
Correct |
8 ms |
8908 KB |
Output is correct |
24 |
Correct |
5 ms |
9000 KB |
Output is correct |
25 |
Correct |
5 ms |
8992 KB |
Output is correct |
26 |
Correct |
5 ms |
8908 KB |
Output is correct |
27 |
Correct |
6 ms |
8980 KB |
Output is correct |
28 |
Correct |
5 ms |
8908 KB |
Output is correct |
29 |
Correct |
5 ms |
8908 KB |
Output is correct |
30 |
Correct |
5 ms |
8996 KB |
Output is correct |
31 |
Correct |
7 ms |
8988 KB |
Output is correct |
32 |
Correct |
5 ms |
8908 KB |
Output is correct |
33 |
Correct |
5 ms |
8908 KB |
Output is correct |
34 |
Correct |
5 ms |
8908 KB |
Output is correct |
35 |
Correct |
5 ms |
8908 KB |
Output is correct |
36 |
Correct |
7 ms |
8988 KB |
Output is correct |
37 |
Correct |
5 ms |
8908 KB |
Output is correct |
38 |
Correct |
6 ms |
8908 KB |
Output is correct |
39 |
Correct |
99 ms |
14436 KB |
Output is correct |
40 |
Correct |
112 ms |
14356 KB |
Output is correct |
41 |
Correct |
140 ms |
14708 KB |
Output is correct |
42 |
Correct |
99 ms |
14784 KB |
Output is correct |
43 |
Correct |
72 ms |
14532 KB |
Output is correct |
44 |
Correct |
53 ms |
14492 KB |
Output is correct |
45 |
Correct |
121 ms |
17988 KB |
Output is correct |
46 |
Correct |
88 ms |
22420 KB |
Output is correct |
47 |
Correct |
151 ms |
19836 KB |
Output is correct |
48 |
Correct |
250 ms |
34140 KB |
Output is correct |
49 |
Correct |
250 ms |
33112 KB |
Output is correct |
50 |
Correct |
169 ms |
19888 KB |
Output is correct |
51 |
Correct |
152 ms |
19892 KB |
Output is correct |
52 |
Correct |
197 ms |
19948 KB |
Output is correct |
53 |
Correct |
254 ms |
18716 KB |
Output is correct |
54 |
Correct |
156 ms |
18756 KB |
Output is correct |
55 |
Correct |
11 ms |
9624 KB |
Output is correct |
56 |
Correct |
12 ms |
9620 KB |
Output is correct |
57 |
Correct |
80 ms |
16416 KB |
Output is correct |
58 |
Correct |
36 ms |
15508 KB |
Output is correct |
59 |
Correct |
98 ms |
23980 KB |
Output is correct |
60 |
Correct |
351 ms |
38680 KB |
Output is correct |
61 |
Correct |
168 ms |
22968 KB |
Output is correct |
62 |
Correct |
183 ms |
22740 KB |
Output is correct |
63 |
Correct |
235 ms |
22948 KB |
Output is correct |
64 |
Correct |
364 ms |
24848 KB |
Output is correct |
65 |
Correct |
193 ms |
23512 KB |
Output is correct |
66 |
Correct |
343 ms |
33732 KB |
Output is correct |
67 |
Correct |
109 ms |
23484 KB |
Output is correct |
68 |
Correct |
211 ms |
24632 KB |
Output is correct |
69 |
Correct |
227 ms |
24760 KB |
Output is correct |
70 |
Correct |
201 ms |
24084 KB |
Output is correct |