# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
376038 |
2021-03-10T19:00:19 Z |
WLZ |
Dreaming (IOI13_dreaming) |
C++14 |
|
69 ms |
17516 KB |
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int cur_cc = 0;
vector< vector< pair<int, int> > > g;
vector<int> cc, d, mn, mx;
void dfs1(int u, int p) {
cc[u] = cur_cc;
for (auto& v : g[u]) {
if (v.first != p) {
d[v.first] = d[u] + v.second;
dfs1(v.first, u);
}
}
mx[u] = d[u];
for (auto& v : g[u]) mx[u] = max(mx[u], mx[v.first]);
}
void dfs2(int u, int p, int len) {
multiset<int> st;
for (auto& v : g[u]) {
if (v.first != p) {
st.insert(mx[v.first]);
}
}
for (auto& v : g[u]) {
if (v.first != p) {
st.erase(mx[v.first]);
dfs2(v.first, u, max(len, (st.empty() ? 0 : *st.rbegin() - d[u])) + v.second);
st.insert(mx[v.first]);
}
}
mn[cc[u]] = min(mn[cc[u]], max(len, mx[u] - d[u]));
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
g.resize(N);
for (int i = 0; i < M; i++) g[A[i]].push_back({B[i], T[i]});
for (int i = 0; i < M; i++) g[B[i]].push_back({A[i], T[i]});
d.assign(N, 0);
cc.assign(N, -1);
mx.resize(N);
for (int i = 0; i < N; i++) {
if (cc[i] == -1) {
dfs1(i, -1);
cur_cc++;
}
}
mn.assign(cur_cc, INF);
for (int i = 0; i < N; i++) {
if (mn[cc[i]] == INF) dfs2(i, -1, 0);
}
sort(mn.begin(), mn.end());
if (cur_cc == 1) return mn[0];
if (cur_cc == 2) return mn[0] + mn[1] + L;
return max({*max_element(mn.begin(), mn.end()), mn[cur_cc - 2] + mn[cur_cc - 3] + 2 * L, mn[cur_cc - 1] + mn[cur_cc - 2] + L});
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
17516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
17516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
6636 KB |
Output is correct |
2 |
Correct |
31 ms |
6636 KB |
Output is correct |
3 |
Correct |
37 ms |
6676 KB |
Output is correct |
4 |
Correct |
40 ms |
6636 KB |
Output is correct |
5 |
Correct |
31 ms |
6636 KB |
Output is correct |
6 |
Correct |
49 ms |
7148 KB |
Output is correct |
7 |
Correct |
33 ms |
6912 KB |
Output is correct |
8 |
Correct |
33 ms |
6508 KB |
Output is correct |
9 |
Correct |
30 ms |
6508 KB |
Output is correct |
10 |
Correct |
39 ms |
6912 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
8 ms |
4352 KB |
Output is correct |
13 |
Correct |
7 ms |
4332 KB |
Output is correct |
14 |
Correct |
7 ms |
4204 KB |
Output is correct |
15 |
Correct |
7 ms |
4332 KB |
Output is correct |
16 |
Correct |
7 ms |
4204 KB |
Output is correct |
17 |
Correct |
7 ms |
4204 KB |
Output is correct |
18 |
Correct |
7 ms |
4332 KB |
Output is correct |
19 |
Correct |
7 ms |
4204 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
7 ms |
4332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
17516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |