# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
284757 |
2020-08-28T02:28:12 Z |
cjoa |
Dreaming (IOI13_dreaming) |
C++11 |
|
73 ms |
16628 KB |
#include "dreaming.h"
#include <vector>
#include <algorithm>
#include <cassert>
#include <iostream>
#include <cstdlib>
using namespace std;
typedef vector<int> VI;
typedef long long llong;
typedef pair<llong,llong> PLL;
struct Edge {
int to, len;
};
vector< vector<Edge> > extract_graph(int N, int M, int A[], int B[], int T[]) {
vector< vector<Edge> > adj(N);
for (int j = 0; j < M; ++j) {
int u = A[j], v = B[j], len = T[j];
adj[u].push_back({v, len});
adj[v].push_back({u, len});
}
return adj;
}
bool is_subtask1(int N, int M, int A[], int B[], int T[], VI& deg) {
if (M != N-2) return false;
deg.assign(N, 0);
for (int j = 0; j < M; ++j) {
int u = A[j], v = B[j];
++deg[u];
++deg[v];
}
for (int u = 0; u < N; ++u)
if (deg[u] > 2)
return false;
return true;
}
void dfs(const vector< vector<Edge> >& G,
vector<bool>& vis,
vector<Edge>& path,
int u) {
vis[u] = true;
for (Edge e : G[u]) {
if (vis[e.to]) continue;
path.push_back(e);
dfs(G, vis, path, e.to);
}
}
const llong INF = 1e18;
PLL get_center_distances(const vector<Edge>& path) {
llong sum_dist = 0;
for (Edge e : path)
sum_dist += e.len;
PLL res(INF, INF);
llong sum_cur_dist = 0;
for (Edge e : path) {
sum_cur_dist += e.len;
PLL cur(sum_cur_dist, sum_dist - sum_cur_dist);
if (cur.first < cur.second)
swap(cur.first, cur.second);
res = min(res, cur);
}
return res;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
vector< vector<Edge> > G = extract_graph(N, M, A, B, T);
VI deg(N);
if (is_subtask1(N, M, A, B, T, deg)) {
vector<bool> vis(N, false);
vector< vector<Edge> > paths;
for (int u = 0; u < N; ++u) {
if (vis[u]) continue;
if (deg[u] == 2) continue;
vector<Edge> path;
dfs(G, vis, path, u);
paths.push_back(path);
/*
cerr << u;
for (Edge e : path)
cerr << " --{" << e.len << "}-- " << e.to;
cerr << endl;
*/
}
assert(paths.size() == 2);
PLL center_dist1 = get_center_distances(paths[0]);
PLL center_dist2 = get_center_distances(paths[1]);
llong res = max(center_dist1.first + center_dist1.second,
center_dist2.first + center_dist2.second);
res = max(res, center_dist1.first + L + center_dist2.second);
return res;
}
assert(false);
return 1 + rand();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
15472 KB |
Output is correct |
2 |
Correct |
73 ms |
16628 KB |
Output is correct |
3 |
Correct |
43 ms |
11244 KB |
Output is correct |
4 |
Correct |
8 ms |
2816 KB |
Output is correct |
5 |
Correct |
8 ms |
1664 KB |
Output is correct |
6 |
Correct |
14 ms |
4092 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
32 ms |
6256 KB |
Output is correct |
9 |
Correct |
35 ms |
8552 KB |
Output is correct |
10 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
15472 KB |
Output is correct |
2 |
Correct |
73 ms |
16628 KB |
Output is correct |
3 |
Correct |
43 ms |
11244 KB |
Output is correct |
4 |
Correct |
8 ms |
2816 KB |
Output is correct |
5 |
Correct |
8 ms |
1664 KB |
Output is correct |
6 |
Correct |
14 ms |
4092 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
32 ms |
6256 KB |
Output is correct |
9 |
Correct |
35 ms |
8552 KB |
Output is correct |
10 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
15472 KB |
Output is correct |
2 |
Correct |
73 ms |
16628 KB |
Output is correct |
3 |
Correct |
43 ms |
11244 KB |
Output is correct |
4 |
Correct |
8 ms |
2816 KB |
Output is correct |
5 |
Correct |
8 ms |
1664 KB |
Output is correct |
6 |
Correct |
14 ms |
4092 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
32 ms |
6256 KB |
Output is correct |
9 |
Correct |
35 ms |
8552 KB |
Output is correct |
10 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
24 ms |
10368 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
15472 KB |
Output is correct |
2 |
Correct |
73 ms |
16628 KB |
Output is correct |
3 |
Correct |
43 ms |
11244 KB |
Output is correct |
4 |
Correct |
8 ms |
2816 KB |
Output is correct |
5 |
Correct |
8 ms |
1664 KB |
Output is correct |
6 |
Correct |
14 ms |
4092 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
32 ms |
6256 KB |
Output is correct |
9 |
Correct |
35 ms |
8552 KB |
Output is correct |
10 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
15472 KB |
Output is correct |
2 |
Correct |
73 ms |
16628 KB |
Output is correct |
3 |
Correct |
43 ms |
11244 KB |
Output is correct |
4 |
Correct |
8 ms |
2816 KB |
Output is correct |
5 |
Correct |
8 ms |
1664 KB |
Output is correct |
6 |
Correct |
14 ms |
4092 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
32 ms |
6256 KB |
Output is correct |
9 |
Correct |
35 ms |
8552 KB |
Output is correct |
10 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |