QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#558756#1152. Dreamingmakrav#0 30ms19724kbC++202.6kb2024-09-11 18:24:332024-09-11 18:24:33

Judging History

你现在查看的是最新测评结果

  • [2024-09-11 18:24:33]
  • 评测
  • 测评结果:0
  • 用时:30ms
  • 内存:19724kb
  • [2024-09-11 18:24:33]
  • 提交

answer

#include "dreaming.h"
#include <iostream>
#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]) {
            if (u == p) continue;
            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);
            cout << i << ' ' << cmin << ' ' << cv << '\n';
            lol.pb({cmin, cv});
        }
    }
    sort(lol.begin(), lol.end());
    for (int i = 0; i < lol.size() - 1; i++) {
        cout << lol[i].second << ' ' << lol.back().second << '\n';
        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);
    int D = 0;
    auto dfs2 = [&](int v, int p, auto&&self) -> void {
        sub[v] = 0;
        vector<int> sbs;
        for (auto &[u, w] : g[v]) {
            if (u != p) {
                self(u, v, self);
                sub[v] = max(sub[v], sub[u] + w);
                sbs.pb(sub[u] + w);
            }
        }
        sort(sbs.begin(), sbs.end());
        D = max(D, sub[v]);
        if (sbs.size() >= 2) {
            D=max(D, sbs.back()+sbs[sbs.size()-2]);
        }
    };
    dfs2(0, 0, dfs2);
    return D;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 27ms
memory: 19724kb

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:

0 255620 53165
39179 10000 39179
39179 53165
511231

result:

wrong answer 1st lines differ - expected: '511231', found: '0 255620 53165'

Subtask #2:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 0ms
memory: 3880kb

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:

0 282 43
19 0 19
19 43
340

result:

wrong answer 1st lines differ - expected: '340', found: '0 282 43'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Wrong Answer

Test #76:

score: 0
Wrong Answer
time: 30ms
memory: 11256kb

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:

0 5 0
1 9 1
2 1 2
3 9 3
4 6 4
5 9 5
6 8 6
7 6 7
8 5 8
9 3 9
10 5 10
11 3 11
12 0 12
13 5 13
14 6 14
15 0 15
16 9 16
17 3 17
18 8 18
19 3 19
20 0 20
21 1 21
22 6 22
23 0 23
24 0 24
25 5 25
26 0 26
27 1 27
28 3 28
29 5 29
30 0 30
31 0 31
32 8 32
33 0 33
34 0 34
35 0 35
36 3 36
37 10 37
38 1 38
39 3 39...

result:

wrong answer 1st lines differ - expected: '19379', found: '0 5 0'

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%