QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#558745 | #1152. Dreaming | makrav# | 0 | 0ms | 0kb | C++20 | 2.0kb | 2024-09-11 18:16:29 | 2024-09-11 18:16:30 |
answer
#include "dreaming.h"
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
int n = N;
int m = M;
int l = L;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
g[A[i]].pb({B[i], T[i]});
g[B[i]].pb({A[i], T[i]});
}
vector<int> used(n, 0), h(n), sub(n);
auto dfs = [&](int v, auto&&self) -> void {
used[v] = 1;
sub[v] = 0;
for (auto &[u, w] : g[v]) {
if (!used[u]) {
h[u] = h[v] + w;
self(u, self);
sub[v] = max(sub[v], sub[u] + w);
}
}
};
int cmin = 1e9 + 1, cv = -1;
auto dfs1 = [&](int v, int p, int up, auto&&self) -> void {
if (max(sub[v], up) < cmin) {
cmin = max(sub[v], up);
cv = v;
}
vector<pair<int, int>> sons;
for (auto [u, w] : g[v]) {
if (u != p) sons.pb({sub[u] + w, u});
}
sort(sons.begin(), sons.end());
for (auto [u, w] : g[v]) {
int newup = up;
if (sons.size() > 1) {
newup = max(newup, (sons.back().second == u ? sons[sons.size() - 2].first : sons.back().first));
}
self(u, v, newup + w, self);
}
};
vector<pair<int, int>> lol;
for (int i = 0; i < n; i++) {
if (!used[i]) {
dfs(i, dfs);
cmin = 1e9 + 1; cv = -1;
dfs1(i, i, 0, dfs1);
lol.pb({cmin, cv});
}
}
sort(lol.begin(), lol.end());
for (int i = 0; i < lol.size() - 1; i++) {
g[lol[i].second].pb({lol.back().second, l});
g[lol.back().second].pb({lol[i].second, l});
}
used.assign(n, 0);h.assign(n, 0);sub.assign(n, 0);
dfs(0, dfs);
cmin = 1e9 + 1; cv = -1;
dfs1(0, 0, 0, dfs1);
return cmin;
}
詳細信息
Subtask #1:
score: 0
Memory Limit Exceeded
Test #1:
score: 0
Memory Limit Exceeded
input:
91188 91186 10000 39179 82675 10000 79545 19393 3 19393 31673 7 31673 40086 4 40086 14128 2 14128 38440 10 38440 40431 4 40431 67403 8 67403 77400 9 77400 21224 10 21224 65903 9 65903 9211 10 9211 37061 2 37061 70742 10 70742 72699 10 72699 11504 3 11504 63531 7 63531 10974 7 10974 17289 9 17289 234...
output:
result:
Subtask #2:
score: 0
Memory Limit Exceeded
Test #14:
score: 0
Memory Limit Exceeded
input:
100 98 1 43 79 282 31 57 4 1 42 1 33 52 2 25 93 1 30 94 1 15 81 2 30 67 2 23 10 4 31 32 1 56 1 1 97 53 5 71 87 2 17 76 4 65 45 3 86 37 3 86 12 2 85 96 1 71 66 2 73 98 5 78 97 3 43 74 1 21 68 5 23 6 5 35 9 1 38 58 2 72 92 1 12 4 5 70 15 2 7 64 5 28 70 2 48 28 5 22 3 2 41 66 5 18 27 4 67 91 4 11 91 3 ...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Memory Limit Exceeded
Test #76:
score: 0
Memory Limit Exceeded
input:
93596 31195 86 4343 1589 8 61155 92883 5 91917 6571 5 32506 33054 1 65199 80366 4 71048 12809 2 32716 43004 9 90865 57094 9 9813 23701 10 45224 84405 5 16380 16918 8 82115 65429 7 80306 41444 6 40398 257 4 61527 7638 9 20232 39859 2 8528 84042 4 21217 74039 5 39362 88045 10 17829 47708 6 5739 10629 ...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%