# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
713893 |
2023-03-23T07:46:40 Z |
kaxzert |
Race (IOI11_race) |
C++17 |
|
450 ms |
81956 KB |
#include<bits/stdc++.h>
using namespace std;
#define fto(i, a, b) for(int i = a; i <= b; ++i)
#define fdto(i, a, b) for(int i = a; i >= b; --i)
#define bugarr(a, i, j) cout << #a << "{" << i << "..." << j << "}:"; fto(k, i, j-1) cout << a[k] << ", "; cout << a[j] << endl;
#define ll long long
#define db double
#define ldb long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define vt vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(i, a) for(auto &i : a)
#define sz(a) (int)a.size()
#define pi(a, b) pair<a, b>
#define fast ios::sync_with_stdio(false); cin.tie(0)
void setIO(string s) {
if (sz(s) != 0) {
freopen((s+".inp").c_str(),"r",stdin);
// freopen((s+".out").c_str(),"w",stdout);
}
}
void setIOusaco(string s) {
if (sz(s) != 0) {
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
}
template<typename T, typename V>
bool ckmin(T &a, V b) {return (b < a)? a = b, true : false;}
template<typename T, typename V>
bool ckmax(T &a, V b) {return (b > a)? a = b, true : false;}
void print(int x) {cout << x;}
void print(long long x) {cout << x;}
void print(unsigned x) {cout << x;}
void print(unsigned long long x) {cout << x;}
void print(double x) {cout << fixed << x;}
void print(long double x) {cout << fixed << x;}
void print(char x) {cout << "'" << x << "'";}
void print(string x) {cout << '"' << x << '"';}
void print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void print(const pair<T, V> &x) {cout << '{'; print(x.ff); cout << ", "; print(x.ss); cout << '}';}
template<typename T>
void print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? ", " : ""), print(i); cout << "}";}
void _print() {cout << "]" << endl;}
template <typename T, typename... V>
void _print(T t, V... v) {print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define bug(x...) cout << "[" << #x << "] = ["; _print(x)
const int maxN = 200007;
set<pair<int, int> > gr[maxN];
int len[maxN], depth[maxN], n, k;
vt<pair<int, int> > ke[maxN];
int ans = (int)1e9;
void dfs(int u, int val, int p = -1) {
len[u] = val;
trav(c, ke[u]) {
int v = c.ff;
int l = c.ss;
if (v == p) continue;
depth[v] = depth[u] + 1;
dfs(v, val+l, u);
}
}
void dfs2(int u, int p = -1) {
trav(c, ke[u]) {
int v = c.ff;
int l = c.ss;
if (v == p) continue;
dfs2(v, u);
gr[v].insert(mp(len[v], depth[v]));
auto it = gr[v].lower_bound(mp(k + len[u], -1));
if (it != gr[v].end() && (it->ff) == k + len[u]) {
ans = min(ans, it->ss - depth[u]);
}
if (sz(gr[u]) < sz(gr[v])) {
swap(gr[u], gr[v]);
}
trav(o, gr[v]) {
int need = k - o.ff + len[u]*2;
auto it = gr[u].lower_bound(mp(need, -1));
if (it != gr[u].end() && (it->ff) == need) {
ans = min(ans, it->ss + o.ss - 2*depth[u]);
}
}
trav(o, gr[v]) gr[u].insert(o);
}
}
int best_path(int n_, int k_, int edges[][2], int weights[]){
//setIO("race_ioi2011");
//ios::sync_with_stdio(false); cin.tie(0);
n = n_;
k = k_;
fto(i, 0, n-2) {
int u = edges[i][0];
int v = edges[i][1];
int l = weights[i];
ke[u].pb(mp(v, l));
ke[v].pb(mp(u, l));
}
dfs(0, 0);
dfs2(0);
return (ans == (int)1e9 ? -1 : ans);
}
//
//int main() {
// setIO("race_ioi2011");
// cin >> n >> k;
// fto(i, 0, n-2) {
// int u, v, l;
// cin >> u >> v >> l;
// ke[u].pb(mp(v, l));
// ke[v].pb(mp(u, l));
// }
//
// dfs(0, 0);
// dfs2(0);
//
// cout << (ans == (int)1e9 ? -1 : ans) << '\n';
// return 0;
//}
Compilation message
race.cpp: In function 'void dfs2(int, int)':
race.cpp:83:7: warning: unused variable 'l' [-Wunused-variable]
83 | int l = c.ss;
| ^
race.cpp: In function 'void setIO(std::string)':
race.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen((s+".inp").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp: In function 'void setIOusaco(std::string)':
race.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen((s+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14356 KB |
Output is correct |
4 |
Correct |
8 ms |
14420 KB |
Output is correct |
5 |
Correct |
8 ms |
14368 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
8 ms |
14320 KB |
Output is correct |
8 |
Correct |
8 ms |
14364 KB |
Output is correct |
9 |
Correct |
8 ms |
14420 KB |
Output is correct |
10 |
Correct |
8 ms |
14380 KB |
Output is correct |
11 |
Correct |
8 ms |
14440 KB |
Output is correct |
12 |
Correct |
7 ms |
14408 KB |
Output is correct |
13 |
Correct |
8 ms |
14420 KB |
Output is correct |
14 |
Correct |
8 ms |
14404 KB |
Output is correct |
15 |
Correct |
8 ms |
14420 KB |
Output is correct |
16 |
Correct |
8 ms |
14404 KB |
Output is correct |
17 |
Correct |
9 ms |
14548 KB |
Output is correct |
18 |
Correct |
10 ms |
14420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14356 KB |
Output is correct |
4 |
Correct |
8 ms |
14420 KB |
Output is correct |
5 |
Correct |
8 ms |
14368 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
8 ms |
14320 KB |
Output is correct |
8 |
Correct |
8 ms |
14364 KB |
Output is correct |
9 |
Correct |
8 ms |
14420 KB |
Output is correct |
10 |
Correct |
8 ms |
14380 KB |
Output is correct |
11 |
Correct |
8 ms |
14440 KB |
Output is correct |
12 |
Correct |
7 ms |
14408 KB |
Output is correct |
13 |
Correct |
8 ms |
14420 KB |
Output is correct |
14 |
Correct |
8 ms |
14404 KB |
Output is correct |
15 |
Correct |
8 ms |
14420 KB |
Output is correct |
16 |
Correct |
8 ms |
14404 KB |
Output is correct |
17 |
Correct |
9 ms |
14548 KB |
Output is correct |
18 |
Correct |
10 ms |
14420 KB |
Output is correct |
19 |
Correct |
8 ms |
14420 KB |
Output is correct |
20 |
Correct |
8 ms |
14420 KB |
Output is correct |
21 |
Correct |
8 ms |
14592 KB |
Output is correct |
22 |
Correct |
8 ms |
14552 KB |
Output is correct |
23 |
Correct |
8 ms |
14532 KB |
Output is correct |
24 |
Correct |
8 ms |
14548 KB |
Output is correct |
25 |
Correct |
8 ms |
14548 KB |
Output is correct |
26 |
Correct |
9 ms |
14644 KB |
Output is correct |
27 |
Correct |
10 ms |
14420 KB |
Output is correct |
28 |
Correct |
11 ms |
14548 KB |
Output is correct |
29 |
Correct |
9 ms |
14548 KB |
Output is correct |
30 |
Correct |
9 ms |
14580 KB |
Output is correct |
31 |
Correct |
8 ms |
14548 KB |
Output is correct |
32 |
Correct |
9 ms |
14548 KB |
Output is correct |
33 |
Correct |
8 ms |
14548 KB |
Output is correct |
34 |
Correct |
8 ms |
14548 KB |
Output is correct |
35 |
Correct |
8 ms |
14548 KB |
Output is correct |
36 |
Correct |
9 ms |
14544 KB |
Output is correct |
37 |
Correct |
8 ms |
14548 KB |
Output is correct |
38 |
Correct |
8 ms |
14548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14356 KB |
Output is correct |
4 |
Correct |
8 ms |
14420 KB |
Output is correct |
5 |
Correct |
8 ms |
14368 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
8 ms |
14320 KB |
Output is correct |
8 |
Correct |
8 ms |
14364 KB |
Output is correct |
9 |
Correct |
8 ms |
14420 KB |
Output is correct |
10 |
Correct |
8 ms |
14380 KB |
Output is correct |
11 |
Correct |
8 ms |
14440 KB |
Output is correct |
12 |
Correct |
7 ms |
14408 KB |
Output is correct |
13 |
Correct |
8 ms |
14420 KB |
Output is correct |
14 |
Correct |
8 ms |
14404 KB |
Output is correct |
15 |
Correct |
8 ms |
14420 KB |
Output is correct |
16 |
Correct |
8 ms |
14404 KB |
Output is correct |
17 |
Correct |
9 ms |
14548 KB |
Output is correct |
18 |
Correct |
10 ms |
14420 KB |
Output is correct |
19 |
Correct |
138 ms |
33536 KB |
Output is correct |
20 |
Correct |
146 ms |
33404 KB |
Output is correct |
21 |
Correct |
123 ms |
33080 KB |
Output is correct |
22 |
Correct |
158 ms |
32460 KB |
Output is correct |
23 |
Correct |
170 ms |
43600 KB |
Output is correct |
24 |
Correct |
115 ms |
35360 KB |
Output is correct |
25 |
Correct |
114 ms |
35132 KB |
Output is correct |
26 |
Correct |
90 ms |
39624 KB |
Output is correct |
27 |
Correct |
195 ms |
40012 KB |
Output is correct |
28 |
Correct |
235 ms |
64168 KB |
Output is correct |
29 |
Correct |
278 ms |
62844 KB |
Output is correct |
30 |
Correct |
204 ms |
40024 KB |
Output is correct |
31 |
Correct |
217 ms |
39952 KB |
Output is correct |
32 |
Correct |
253 ms |
40100 KB |
Output is correct |
33 |
Correct |
193 ms |
36440 KB |
Output is correct |
34 |
Correct |
332 ms |
60352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14356 KB |
Output is correct |
4 |
Correct |
8 ms |
14420 KB |
Output is correct |
5 |
Correct |
8 ms |
14368 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
8 ms |
14320 KB |
Output is correct |
8 |
Correct |
8 ms |
14364 KB |
Output is correct |
9 |
Correct |
8 ms |
14420 KB |
Output is correct |
10 |
Correct |
8 ms |
14380 KB |
Output is correct |
11 |
Correct |
8 ms |
14440 KB |
Output is correct |
12 |
Correct |
7 ms |
14408 KB |
Output is correct |
13 |
Correct |
8 ms |
14420 KB |
Output is correct |
14 |
Correct |
8 ms |
14404 KB |
Output is correct |
15 |
Correct |
8 ms |
14420 KB |
Output is correct |
16 |
Correct |
8 ms |
14404 KB |
Output is correct |
17 |
Correct |
9 ms |
14548 KB |
Output is correct |
18 |
Correct |
10 ms |
14420 KB |
Output is correct |
19 |
Correct |
8 ms |
14420 KB |
Output is correct |
20 |
Correct |
8 ms |
14420 KB |
Output is correct |
21 |
Correct |
8 ms |
14592 KB |
Output is correct |
22 |
Correct |
8 ms |
14552 KB |
Output is correct |
23 |
Correct |
8 ms |
14532 KB |
Output is correct |
24 |
Correct |
8 ms |
14548 KB |
Output is correct |
25 |
Correct |
8 ms |
14548 KB |
Output is correct |
26 |
Correct |
9 ms |
14644 KB |
Output is correct |
27 |
Correct |
10 ms |
14420 KB |
Output is correct |
28 |
Correct |
11 ms |
14548 KB |
Output is correct |
29 |
Correct |
9 ms |
14548 KB |
Output is correct |
30 |
Correct |
9 ms |
14580 KB |
Output is correct |
31 |
Correct |
8 ms |
14548 KB |
Output is correct |
32 |
Correct |
9 ms |
14548 KB |
Output is correct |
33 |
Correct |
8 ms |
14548 KB |
Output is correct |
34 |
Correct |
8 ms |
14548 KB |
Output is correct |
35 |
Correct |
8 ms |
14548 KB |
Output is correct |
36 |
Correct |
9 ms |
14544 KB |
Output is correct |
37 |
Correct |
8 ms |
14548 KB |
Output is correct |
38 |
Correct |
8 ms |
14548 KB |
Output is correct |
39 |
Correct |
138 ms |
33536 KB |
Output is correct |
40 |
Correct |
146 ms |
33404 KB |
Output is correct |
41 |
Correct |
123 ms |
33080 KB |
Output is correct |
42 |
Correct |
158 ms |
32460 KB |
Output is correct |
43 |
Correct |
170 ms |
43600 KB |
Output is correct |
44 |
Correct |
115 ms |
35360 KB |
Output is correct |
45 |
Correct |
114 ms |
35132 KB |
Output is correct |
46 |
Correct |
90 ms |
39624 KB |
Output is correct |
47 |
Correct |
195 ms |
40012 KB |
Output is correct |
48 |
Correct |
235 ms |
64168 KB |
Output is correct |
49 |
Correct |
278 ms |
62844 KB |
Output is correct |
50 |
Correct |
204 ms |
40024 KB |
Output is correct |
51 |
Correct |
217 ms |
39952 KB |
Output is correct |
52 |
Correct |
253 ms |
40100 KB |
Output is correct |
53 |
Correct |
193 ms |
36440 KB |
Output is correct |
54 |
Correct |
332 ms |
60352 KB |
Output is correct |
55 |
Correct |
19 ms |
16852 KB |
Output is correct |
56 |
Correct |
16 ms |
15828 KB |
Output is correct |
57 |
Correct |
80 ms |
30000 KB |
Output is correct |
58 |
Correct |
65 ms |
26020 KB |
Output is correct |
59 |
Correct |
98 ms |
39628 KB |
Output is correct |
60 |
Correct |
310 ms |
63376 KB |
Output is correct |
61 |
Correct |
366 ms |
44104 KB |
Output is correct |
62 |
Correct |
305 ms |
40108 KB |
Output is correct |
63 |
Correct |
256 ms |
39920 KB |
Output is correct |
64 |
Correct |
450 ms |
81956 KB |
Output is correct |
65 |
Correct |
437 ms |
76412 KB |
Output is correct |
66 |
Correct |
234 ms |
59656 KB |
Output is correct |
67 |
Correct |
192 ms |
37692 KB |
Output is correct |
68 |
Correct |
352 ms |
52736 KB |
Output is correct |
69 |
Correct |
328 ms |
57020 KB |
Output is correct |
70 |
Correct |
351 ms |
51428 KB |
Output is correct |