# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
59244 |
2018-07-21T10:11:08 Z |
aome |
Dreaming (IOI13_dreaming) |
C++17 |
|
53 ms |
11892 KB |
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int INF = 1e9;
int f[N], g[N];
bool visit[N];
vector<int> vec;
vector< pair<int, int> > G[N];
void dfs1(int u, int p) {
visit[u] = 1, vec.push_back(u);
for (auto i : G[u]) {
int v = i.first, w = i.second;
if (v == p) continue;
dfs1(v, u);
f[u] = max(f[u], f[v] + w);
}
}
void dfs2(int u, int p) {
int v0 = -INF, v1 = -INF;
for (auto i : G[u]) {
int v = i.first, w = i.second;
if (v == p) continue;
int tmp = f[v] + w;
if (v0 < tmp) v1 = v0, v0 = tmp;
else if (v1 < tmp) v1 = tmp;
}
for (auto i : G[u]) {
int v = i.first, w = i.second;
if (v == p) continue;
g[v] = g[u] + w;
if (v0 == f[v] + w) g[v] = max(g[v], v1 + w);
else g[v] = max(g[v], v0 + w);
dfs2(v, u);
}
}
int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
for (int i = 0; i < m; ++i) {
G[A[i]].push_back({B[i], T[i]});
G[B[i]].push_back({A[i], T[i]});
}
vector<int> vec2;
for (int i = 0; i < n; ++i) {
if (visit[i]) continue;
vec.clear(), dfs1(i, i), dfs2(i, i);
int mn = INF;
for (auto j : vec) mn = min(mn, max(f[j], g[j]));
vec2.push_back(mn);
}
sort(vec2.begin(), vec2.end(), greater<int>());
if (vec2.size() == 1) {
return vec2[0];
}
if (vec2.size() == 2) {
return vec2[0] + vec2[1] + L;
}
return max(vec2[0] + vec2[1] + L, vec2[1] + vec2[2] + 2 * L);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
11892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
11892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
11892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
6268 KB |
Output is correct |
2 |
Correct |
27 ms |
6268 KB |
Output is correct |
3 |
Correct |
31 ms |
6184 KB |
Output is correct |
4 |
Correct |
25 ms |
6264 KB |
Output is correct |
5 |
Correct |
32 ms |
6264 KB |
Output is correct |
6 |
Correct |
29 ms |
6656 KB |
Output is correct |
7 |
Correct |
29 ms |
6400 KB |
Output is correct |
8 |
Correct |
32 ms |
6080 KB |
Output is correct |
9 |
Correct |
27 ms |
6132 KB |
Output is correct |
10 |
Correct |
32 ms |
6388 KB |
Output is correct |
11 |
Correct |
4 ms |
2688 KB |
Output is correct |
12 |
Correct |
8 ms |
4092 KB |
Output is correct |
13 |
Correct |
7 ms |
4092 KB |
Output is correct |
14 |
Correct |
7 ms |
3964 KB |
Output is correct |
15 |
Correct |
7 ms |
3964 KB |
Output is correct |
16 |
Correct |
7 ms |
3964 KB |
Output is correct |
17 |
Correct |
7 ms |
3580 KB |
Output is correct |
18 |
Correct |
8 ms |
4092 KB |
Output is correct |
19 |
Correct |
7 ms |
3964 KB |
Output is correct |
20 |
Correct |
3 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
7 ms |
3964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
11892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
11892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |