Submission #785768

# Submission time Handle Problem Language Result Execution time Memory
785768 2023-07-17T14:54:16 Z drdilyor Dreaming (IOI13_dreaming) C++17
47 / 100
106 ms 20172 KB
#include<bits/stdc++.h>
#include"dreaming.h"
using namespace std;

struct DSU {
    int n;
    vector<int> parent;
    vector<int> size;

    DSU(int n) : n(n), parent(n), size(n, 1) {
        iota(parent.begin(), parent.end(), 0);
    }

    int get(int i) {
        return parent[i] == i ? i : parent[i] = get(parent[i]);
    }

    void merge(int v, int u) {
        v = get(v);
        u = get(u);
        if (u == v) return;
        if (size[v] < size[u]) swap(v, u);
        parent[u] = v;
        size[v] += size[u];
    }
};


int travelTime(int n, int m, int l, int a[], int b[], int t[]) {

    DSU cc(n);
    vector<vector<pair<int,int>>> aadj(n);
    for (int i = 0; i < m;i ++) {
        aadj[a[i]].push_back({b[i], t[i]});
        aadj[b[i]].push_back({a[i], t[i]});
        cc.merge(a[i], b[i]);
    }

    vector<vector<int>> comps(n);
    for (int i = 0; i < n;i++) {
        comps[cc.get(i)].push_back(i);
    }
    for (auto& i : comps)
        sort(i.begin(), i.end());

    vector<int> ccompress;
    for (int i = 0; i < n;i++) {
        if (cc.get(i) == i)
            ccompress.push_back(i);
    }
    sort(ccompress.begin(), ccompress.end());
    int k = ccompress.size();

    vector<vector<vector<pair<int,int>>>> adj(k);
    for (int i = 0; i < k; i++) {
        adj[i].resize(comps[ccompress[i]].size());
    }

    for (int i = 0; i <m; i++) {
        int u = a[i], v = b[i];
        auto& xs = comps[cc.get(u)];
        u = lower_bound(xs.begin(), xs.end(), u) - xs.begin();
        v = lower_bound(xs.begin(), xs.end(), v) - xs.begin();
        int tree_index = lower_bound(ccompress.begin(), ccompress.end(), cc.get(a[i])) - ccompress.begin();
        adj[tree_index][v].push_back({u, t[i]});
        adj[tree_index][u].push_back({v, t[i]});
    }

    vector<int> center(k);
    vector<int> mxdist(k);

    int inner_dist = 0;
    for (int tree = 0; tree < k; tree++) {
        auto dfs = [&](
                auto& dfs,
                int t,
                vector<int>& dist,
                int i, int p=-1, int w=0)->void{
            dist[i] = w;
            for (auto [e, ew] : adj[t][i]) {
                if (e == p) continue;
                dfs(dfs, t, dist, e, i, w + ew);
            }
        };
        int tn = adj[tree].size();

        vector<int> dist(tn);

        dfs(dfs, tree, dist, 0);
        int s1 = max_element(dist.begin(), dist.end()) - dist.begin();
        dfs(dfs, tree, dist, s1);
        int s2 = max_element(dist.begin(), dist.end()) - dist.begin();

        inner_dist = max(inner_dist, dist[s2]);
        vector<int> dist2(tn);
        dfs(dfs, tree, dist2, s2);
        for (int i = 0; i < tn; i++)
            dist[i] = max(dist[i], dist2[i]);

        center[tree] = min_element(dist.begin(), dist.end()) - dist.begin();

        dfs(dfs, tree, dist, center[tree]);
        sort(dist.begin(), dist.end(), greater());
        mxdist[tree] = dist[0];
    }
    multiset<int> st(mxdist.begin(), mxdist.end());
    while (st.size() > 1) {
        // for (int i : st) cout << i << ' ';cout << endl;
        int a = *st.begin();
        st.erase(st.begin());
        int b = *st.begin();
        st.erase(st.begin());
        inner_dist = max(inner_dist, a + b + l);
        st.insert(min(
                    max(a + l, b),
                    max(a, b + l)
                ));
    }
    return max(inner_dist, *st.begin());
}
# Verdict Execution time Memory Grader output
1 Correct 75 ms 18252 KB Output is correct
2 Correct 75 ms 18196 KB Output is correct
3 Correct 47 ms 11976 KB Output is correct
4 Correct 10 ms 2920 KB Output is correct
5 Correct 8 ms 2004 KB Output is correct
6 Correct 17 ms 4168 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 39 ms 7492 KB Output is correct
9 Correct 45 ms 9704 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 66 ms 13256 KB Output is correct
12 Correct 77 ms 15764 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 18252 KB Output is correct
2 Correct 75 ms 18196 KB Output is correct
3 Correct 47 ms 11976 KB Output is correct
4 Correct 10 ms 2920 KB Output is correct
5 Correct 8 ms 2004 KB Output is correct
6 Correct 17 ms 4168 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 39 ms 7492 KB Output is correct
9 Correct 45 ms 9704 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 66 ms 13256 KB Output is correct
12 Correct 77 ms 15764 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 75 ms 18288 KB Output is correct
40 Correct 75 ms 18188 KB Output is correct
41 Correct 50 ms 12044 KB Output is correct
42 Correct 10 ms 2972 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 256 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 96 ms 17952 KB Output is correct
58 Correct 104 ms 17604 KB Output is correct
59 Correct 98 ms 17936 KB Output is correct
60 Correct 97 ms 17468 KB Output is correct
61 Correct 98 ms 17976 KB Output is correct
62 Correct 100 ms 17612 KB Output is correct
63 Correct 90 ms 17740 KB Output is correct
64 Correct 91 ms 17816 KB Output is correct
65 Correct 93 ms 17780 KB Output is correct
66 Correct 93 ms 17760 KB Output is correct
67 Correct 98 ms 17776 KB Output is correct
68 Correct 99 ms 17896 KB Output is correct
69 Correct 100 ms 17608 KB Output is correct
70 Correct 101 ms 17576 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 2 ms 724 KB Output is correct
73 Correct 3 ms 724 KB Output is correct
74 Correct 2 ms 724 KB Output is correct
75 Correct 2 ms 724 KB Output is correct
76 Correct 3 ms 852 KB Output is correct
77 Correct 2 ms 724 KB Output is correct
78 Correct 2 ms 724 KB Output is correct
79 Correct 2 ms 724 KB Output is correct
80 Correct 98 ms 17548 KB Output is correct
81 Correct 106 ms 17656 KB Output is correct
82 Correct 95 ms 17876 KB Output is correct
83 Correct 97 ms 17908 KB Output is correct
84 Correct 2 ms 724 KB Output is correct
85 Correct 2 ms 596 KB Output is correct
86 Correct 2 ms 724 KB Output is correct
87 Correct 2 ms 724 KB Output is correct
88 Correct 2 ms 724 KB Output is correct
89 Correct 2 ms 724 KB Output is correct
90 Correct 2 ms 724 KB Output is correct
91 Correct 2 ms 724 KB Output is correct
92 Correct 2 ms 724 KB Output is correct
93 Correct 2 ms 724 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 0 ms 212 KB Output is correct
98 Correct 0 ms 212 KB Output is correct
99 Correct 1 ms 212 KB Output is correct
100 Correct 0 ms 212 KB Output is correct
101 Correct 0 ms 212 KB Output is correct
102 Correct 1 ms 212 KB Output is correct
103 Correct 0 ms 212 KB Output is correct
104 Correct 8 ms 2004 KB Output is correct
105 Correct 17 ms 4256 KB Output is correct
106 Correct 1 ms 340 KB Output is correct
107 Correct 37 ms 7576 KB Output is correct
108 Correct 46 ms 9740 KB Output is correct
109 Correct 1 ms 340 KB Output is correct
110 Correct 66 ms 13156 KB Output is correct
111 Correct 78 ms 15752 KB Output is correct
112 Correct 1 ms 468 KB Output is correct
113 Correct 102 ms 20000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 19708 KB Output is correct
2 Incorrect 59 ms 20172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Incorrect 1 ms 468 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 75 ms 18252 KB Output is correct
2 Correct 75 ms 18196 KB Output is correct
3 Correct 47 ms 11976 KB Output is correct
4 Correct 10 ms 2920 KB Output is correct
5 Correct 8 ms 2004 KB Output is correct
6 Correct 17 ms 4168 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 39 ms 7492 KB Output is correct
9 Correct 45 ms 9704 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 66 ms 13256 KB Output is correct
12 Correct 77 ms 15764 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 75 ms 18288 KB Output is correct
40 Correct 75 ms 18188 KB Output is correct
41 Correct 50 ms 12044 KB Output is correct
42 Correct 10 ms 2972 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 256 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 96 ms 17952 KB Output is correct
58 Correct 104 ms 17604 KB Output is correct
59 Correct 98 ms 17936 KB Output is correct
60 Correct 97 ms 17468 KB Output is correct
61 Correct 98 ms 17976 KB Output is correct
62 Correct 100 ms 17612 KB Output is correct
63 Correct 90 ms 17740 KB Output is correct
64 Correct 91 ms 17816 KB Output is correct
65 Correct 93 ms 17780 KB Output is correct
66 Correct 93 ms 17760 KB Output is correct
67 Correct 98 ms 17776 KB Output is correct
68 Correct 99 ms 17896 KB Output is correct
69 Correct 100 ms 17608 KB Output is correct
70 Correct 101 ms 17576 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 2 ms 724 KB Output is correct
73 Correct 3 ms 724 KB Output is correct
74 Correct 2 ms 724 KB Output is correct
75 Correct 2 ms 724 KB Output is correct
76 Correct 3 ms 852 KB Output is correct
77 Correct 2 ms 724 KB Output is correct
78 Correct 2 ms 724 KB Output is correct
79 Correct 2 ms 724 KB Output is correct
80 Correct 98 ms 17548 KB Output is correct
81 Correct 106 ms 17656 KB Output is correct
82 Correct 95 ms 17876 KB Output is correct
83 Correct 97 ms 17908 KB Output is correct
84 Correct 2 ms 724 KB Output is correct
85 Correct 2 ms 596 KB Output is correct
86 Correct 2 ms 724 KB Output is correct
87 Correct 2 ms 724 KB Output is correct
88 Correct 2 ms 724 KB Output is correct
89 Correct 2 ms 724 KB Output is correct
90 Correct 2 ms 724 KB Output is correct
91 Correct 2 ms 724 KB Output is correct
92 Correct 2 ms 724 KB Output is correct
93 Correct 2 ms 724 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 0 ms 212 KB Output is correct
98 Correct 0 ms 212 KB Output is correct
99 Correct 1 ms 212 KB Output is correct
100 Correct 0 ms 212 KB Output is correct
101 Correct 0 ms 212 KB Output is correct
102 Correct 1 ms 212 KB Output is correct
103 Correct 0 ms 212 KB Output is correct
104 Correct 8 ms 2004 KB Output is correct
105 Correct 17 ms 4256 KB Output is correct
106 Correct 1 ms 340 KB Output is correct
107 Correct 37 ms 7576 KB Output is correct
108 Correct 46 ms 9740 KB Output is correct
109 Correct 1 ms 340 KB Output is correct
110 Correct 66 ms 13156 KB Output is correct
111 Correct 78 ms 15752 KB Output is correct
112 Correct 1 ms 468 KB Output is correct
113 Correct 102 ms 20000 KB Output is correct
114 Correct 59 ms 19708 KB Output is correct
115 Incorrect 59 ms 20172 KB Output isn't correct
116 Halted 0 ms 0 KB -