Submission #561124

# Submission time Handle Problem Language Result Execution time Memory
561124 2022-05-12T09:54:43 Z Zanite Dreaming (IOI13_dreaming) C++17
65 / 100
112 ms 23484 KB
#include "dreaming.h"

#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define fi first
#define se second

const int INF = 2e9;
const int maxN = 1e5 + 5;

void chmax(int &a, int b) {a = max(a, b);}
void chmin(int &a, int b) {a = min(a, b);}

struct Node {
    int child, lg;
    Node(int _child, int _lg) :
        child(_child),
        lg(_lg)
    {}

    bool operator < (const Node &other) const {
        return lg > other.lg;
    }
};

int N, M, L, ans;
vector<pii> adj[maxN];
vector<Node> children[maxN];
int idx[maxN], longest[maxN], newLongest[maxN];

vector<int> curComponent, components;
void dfs(int cur, int par, int id) {
    idx[cur] = id;
	curComponent.push_back(cur);

    for (auto a : adj[cur]) {
        int nxt, w;
        tie(nxt, w) = a;
        if (nxt == par) continue;

        dfs(nxt, cur, id);
        chmax(longest[cur], longest[nxt] + w);
        children[cur].push_back(Node(nxt, longest[nxt] + w));
    }
}

void reroot(int cur, int par, int downwardsEdge) {
    if (par != -1) {
        // push "parent" as cur's child
        if (children[par][0].child == cur) {
            if (children[par].size() > 1) {
                children[cur].push_back(Node(par, children[par][1].lg + downwardsEdge));
            } else {
                children[cur].push_back(Node(par, downwardsEdge));
            }
            
        } else {
            children[cur].push_back(Node(par, children[par][0].lg + downwardsEdge));
        }
    }

	sort(children[cur].begin(), children[cur].end());

	// update newLongest
	for (auto c : children[cur]) {
		chmax(newLongest[cur], c.lg);
	}

	// go to children
	for (auto a : adj[cur]) {
		int nxt, w;
		tie(nxt, w) = a;
		if (nxt == par) continue;

		reroot(nxt, cur, w);
	}
}

void calculateTree(int root, int id) {
    // gather data about longest and children's longest for each node
	curComponent.clear();
    dfs(root, -1, id);

    // do reroot
    reroot(root, -1, -1);

	// find out the minimum newLongest of the component
	int curMin = INF;
	for (auto i : curComponent) {
		chmax(ans, newLongest[i]);
		chmin(curMin, newLongest[i]);
	}
	components.push_back(curMin);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	if (M == N - 1) return 0;

    for (int i = 0; i < M; i++) {
        adj[A[i]].push_back({B[i], T[i]});
        adj[B[i]].push_back({A[i], T[i]});
    }

    for (int i = 0, cur = 1; i < N; i++) {
        if (idx[i] == 0) {
            calculateTree(i, cur);
            cur++;
        }
    }

	sort(components.begin(), components.end());
	int s = components.size();

	chmax(ans, components[s-1] + components[s-2] + L);
	if (s > 2) {
		chmax(ans, components[s-2] + components[s-3] + (L << 1));
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 64 ms 18120 KB Output is correct
2 Correct 65 ms 17736 KB Output is correct
3 Correct 41 ms 15340 KB Output is correct
4 Correct 10 ms 6996 KB Output is correct
5 Correct 9 ms 6228 KB Output is correct
6 Correct 16 ms 7884 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 31 ms 10504 KB Output is correct
9 Correct 37 ms 13204 KB Output is correct
10 Correct 3 ms 5020 KB Output is correct
11 Correct 59 ms 14584 KB Output is correct
12 Correct 69 ms 16260 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 5012 KB Output is correct
7 Correct 4 ms 5012 KB Output is correct
8 Correct 4 ms 5012 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 5012 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5008 KB Output is correct
14 Correct 3 ms 5012 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5008 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5008 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 18120 KB Output is correct
2 Correct 65 ms 17736 KB Output is correct
3 Correct 41 ms 15340 KB Output is correct
4 Correct 10 ms 6996 KB Output is correct
5 Correct 9 ms 6228 KB Output is correct
6 Correct 16 ms 7884 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 31 ms 10504 KB Output is correct
9 Correct 37 ms 13204 KB Output is correct
10 Correct 3 ms 5020 KB Output is correct
11 Correct 59 ms 14584 KB Output is correct
12 Correct 69 ms 16260 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5012 KB Output is correct
20 Correct 4 ms 5012 KB Output is correct
21 Correct 4 ms 5012 KB Output is correct
22 Correct 3 ms 5012 KB Output is correct
23 Correct 3 ms 5012 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5008 KB Output is correct
27 Correct 3 ms 5012 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 5008 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 5008 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 64 ms 18100 KB Output is correct
40 Correct 67 ms 17848 KB Output is correct
41 Correct 40 ms 15336 KB Output is correct
42 Correct 10 ms 6996 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 5008 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 5012 KB Output is correct
50 Correct 3 ms 5008 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 3 ms 5016 KB Output is correct
53 Correct 3 ms 5008 KB Output is correct
54 Correct 3 ms 5016 KB Output is correct
55 Correct 3 ms 5012 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 92 ms 15096 KB Output is correct
58 Correct 90 ms 14996 KB Output is correct
59 Correct 97 ms 15172 KB Output is correct
60 Correct 91 ms 14996 KB Output is correct
61 Correct 89 ms 15264 KB Output is correct
62 Correct 88 ms 15108 KB Output is correct
63 Correct 84 ms 15244 KB Output is correct
64 Correct 86 ms 15292 KB Output is correct
65 Correct 86 ms 15300 KB Output is correct
66 Correct 94 ms 15324 KB Output is correct
67 Correct 104 ms 15108 KB Output is correct
68 Correct 93 ms 15172 KB Output is correct
69 Correct 90 ms 15068 KB Output is correct
70 Correct 91 ms 14980 KB Output is correct
71 Correct 2 ms 4948 KB Output is correct
72 Correct 5 ms 5332 KB Output is correct
73 Correct 5 ms 5316 KB Output is correct
74 Correct 5 ms 5332 KB Output is correct
75 Correct 4 ms 5316 KB Output is correct
76 Correct 5 ms 5280 KB Output is correct
77 Correct 5 ms 5332 KB Output is correct
78 Correct 5 ms 5332 KB Output is correct
79 Correct 5 ms 5332 KB Output is correct
80 Correct 94 ms 15060 KB Output is correct
81 Correct 112 ms 15064 KB Output is correct
82 Correct 89 ms 15212 KB Output is correct
83 Correct 86 ms 15348 KB Output is correct
84 Correct 4 ms 5280 KB Output is correct
85 Correct 4 ms 5280 KB Output is correct
86 Correct 4 ms 5204 KB Output is correct
87 Correct 4 ms 5204 KB Output is correct
88 Correct 5 ms 5332 KB Output is correct
89 Correct 4 ms 5204 KB Output is correct
90 Correct 4 ms 5316 KB Output is correct
91 Correct 5 ms 5332 KB Output is correct
92 Correct 4 ms 5332 KB Output is correct
93 Correct 4 ms 5204 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 5012 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 3 ms 5008 KB Output is correct
98 Correct 3 ms 4948 KB Output is correct
99 Correct 3 ms 4948 KB Output is correct
100 Correct 3 ms 4948 KB Output is correct
101 Correct 3 ms 5012 KB Output is correct
102 Correct 3 ms 5012 KB Output is correct
103 Correct 3 ms 4948 KB Output is correct
104 Correct 9 ms 6228 KB Output is correct
105 Correct 18 ms 7932 KB Output is correct
106 Correct 3 ms 5012 KB Output is correct
107 Correct 28 ms 10452 KB Output is correct
108 Correct 43 ms 13204 KB Output is correct
109 Correct 4 ms 5076 KB Output is correct
110 Correct 62 ms 14592 KB Output is correct
111 Correct 73 ms 16268 KB Output is correct
112 Correct 3 ms 5156 KB Output is correct
113 Correct 92 ms 23484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 10716 KB Output is correct
2 Correct 31 ms 10808 KB Output is correct
3 Correct 31 ms 10680 KB Output is correct
4 Correct 33 ms 10764 KB Output is correct
5 Correct 30 ms 10740 KB Output is correct
6 Correct 31 ms 11288 KB Output is correct
7 Correct 30 ms 10952 KB Output is correct
8 Correct 27 ms 10588 KB Output is correct
9 Correct 31 ms 10512 KB Output is correct
10 Correct 31 ms 10868 KB Output is correct
11 Correct 3 ms 5012 KB Output is correct
12 Correct 10 ms 6680 KB Output is correct
13 Correct 7 ms 6736 KB Output is correct
14 Correct 7 ms 6668 KB Output is correct
15 Correct 7 ms 6608 KB Output is correct
16 Correct 7 ms 6732 KB Output is correct
17 Correct 6 ms 6224 KB Output is correct
18 Correct 7 ms 6736 KB Output is correct
19 Correct 7 ms 6672 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 10 ms 6668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 5012 KB Output is correct
7 Correct 4 ms 5012 KB Output is correct
8 Correct 4 ms 5012 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 5012 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5008 KB Output is correct
14 Correct 3 ms 5012 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5008 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5008 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 4 ms 5332 KB Output is correct
28 Correct 4 ms 5276 KB Output is correct
29 Correct 3 ms 5020 KB Output is correct
30 Correct 4 ms 5152 KB Output is correct
31 Correct 5 ms 5276 KB Output is correct
32 Correct 3 ms 5020 KB Output is correct
33 Correct 4 ms 5204 KB Output is correct
34 Correct 5 ms 5332 KB Output is correct
35 Correct 3 ms 5016 KB Output is correct
36 Correct 3 ms 5016 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 4 ms 4948 KB Output is correct
39 Correct 4 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 5012 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 5012 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 3 ms 4948 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Incorrect 4 ms 5020 KB Output isn't correct
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 18120 KB Output is correct
2 Correct 65 ms 17736 KB Output is correct
3 Correct 41 ms 15340 KB Output is correct
4 Correct 10 ms 6996 KB Output is correct
5 Correct 9 ms 6228 KB Output is correct
6 Correct 16 ms 7884 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 31 ms 10504 KB Output is correct
9 Correct 37 ms 13204 KB Output is correct
10 Correct 3 ms 5020 KB Output is correct
11 Correct 59 ms 14584 KB Output is correct
12 Correct 69 ms 16260 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5012 KB Output is correct
20 Correct 4 ms 5012 KB Output is correct
21 Correct 4 ms 5012 KB Output is correct
22 Correct 3 ms 5012 KB Output is correct
23 Correct 3 ms 5012 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5008 KB Output is correct
27 Correct 3 ms 5012 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 5008 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 5008 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 64 ms 18100 KB Output is correct
40 Correct 67 ms 17848 KB Output is correct
41 Correct 40 ms 15336 KB Output is correct
42 Correct 10 ms 6996 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 5008 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 5012 KB Output is correct
50 Correct 3 ms 5008 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 3 ms 5016 KB Output is correct
53 Correct 3 ms 5008 KB Output is correct
54 Correct 3 ms 5016 KB Output is correct
55 Correct 3 ms 5012 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 92 ms 15096 KB Output is correct
58 Correct 90 ms 14996 KB Output is correct
59 Correct 97 ms 15172 KB Output is correct
60 Correct 91 ms 14996 KB Output is correct
61 Correct 89 ms 15264 KB Output is correct
62 Correct 88 ms 15108 KB Output is correct
63 Correct 84 ms 15244 KB Output is correct
64 Correct 86 ms 15292 KB Output is correct
65 Correct 86 ms 15300 KB Output is correct
66 Correct 94 ms 15324 KB Output is correct
67 Correct 104 ms 15108 KB Output is correct
68 Correct 93 ms 15172 KB Output is correct
69 Correct 90 ms 15068 KB Output is correct
70 Correct 91 ms 14980 KB Output is correct
71 Correct 2 ms 4948 KB Output is correct
72 Correct 5 ms 5332 KB Output is correct
73 Correct 5 ms 5316 KB Output is correct
74 Correct 5 ms 5332 KB Output is correct
75 Correct 4 ms 5316 KB Output is correct
76 Correct 5 ms 5280 KB Output is correct
77 Correct 5 ms 5332 KB Output is correct
78 Correct 5 ms 5332 KB Output is correct
79 Correct 5 ms 5332 KB Output is correct
80 Correct 94 ms 15060 KB Output is correct
81 Correct 112 ms 15064 KB Output is correct
82 Correct 89 ms 15212 KB Output is correct
83 Correct 86 ms 15348 KB Output is correct
84 Correct 4 ms 5280 KB Output is correct
85 Correct 4 ms 5280 KB Output is correct
86 Correct 4 ms 5204 KB Output is correct
87 Correct 4 ms 5204 KB Output is correct
88 Correct 5 ms 5332 KB Output is correct
89 Correct 4 ms 5204 KB Output is correct
90 Correct 4 ms 5316 KB Output is correct
91 Correct 5 ms 5332 KB Output is correct
92 Correct 4 ms 5332 KB Output is correct
93 Correct 4 ms 5204 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 5012 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 3 ms 5008 KB Output is correct
98 Correct 3 ms 4948 KB Output is correct
99 Correct 3 ms 4948 KB Output is correct
100 Correct 3 ms 4948 KB Output is correct
101 Correct 3 ms 5012 KB Output is correct
102 Correct 3 ms 5012 KB Output is correct
103 Correct 3 ms 4948 KB Output is correct
104 Correct 9 ms 6228 KB Output is correct
105 Correct 18 ms 7932 KB Output is correct
106 Correct 3 ms 5012 KB Output is correct
107 Correct 28 ms 10452 KB Output is correct
108 Correct 43 ms 13204 KB Output is correct
109 Correct 4 ms 5076 KB Output is correct
110 Correct 62 ms 14592 KB Output is correct
111 Correct 73 ms 16268 KB Output is correct
112 Correct 3 ms 5156 KB Output is correct
113 Correct 92 ms 23484 KB Output is correct
114 Correct 30 ms 10716 KB Output is correct
115 Correct 31 ms 10808 KB Output is correct
116 Correct 31 ms 10680 KB Output is correct
117 Correct 33 ms 10764 KB Output is correct
118 Correct 30 ms 10740 KB Output is correct
119 Correct 31 ms 11288 KB Output is correct
120 Correct 30 ms 10952 KB Output is correct
121 Correct 27 ms 10588 KB Output is correct
122 Correct 31 ms 10512 KB Output is correct
123 Correct 31 ms 10868 KB Output is correct
124 Correct 3 ms 5012 KB Output is correct
125 Correct 10 ms 6680 KB Output is correct
126 Correct 7 ms 6736 KB Output is correct
127 Correct 7 ms 6668 KB Output is correct
128 Correct 7 ms 6608 KB Output is correct
129 Correct 7 ms 6732 KB Output is correct
130 Correct 6 ms 6224 KB Output is correct
131 Correct 7 ms 6736 KB Output is correct
132 Correct 7 ms 6672 KB Output is correct
133 Correct 3 ms 4948 KB Output is correct
134 Correct 3 ms 5016 KB Output is correct
135 Correct 3 ms 5076 KB Output is correct
136 Correct 10 ms 6668 KB Output is correct
137 Correct 3 ms 5076 KB Output is correct
138 Correct 4 ms 5332 KB Output is correct
139 Correct 4 ms 5276 KB Output is correct
140 Correct 3 ms 5020 KB Output is correct
141 Correct 4 ms 5152 KB Output is correct
142 Correct 5 ms 5276 KB Output is correct
143 Correct 3 ms 5020 KB Output is correct
144 Correct 4 ms 5204 KB Output is correct
145 Correct 5 ms 5332 KB Output is correct
146 Correct 3 ms 5016 KB Output is correct
147 Correct 3 ms 5016 KB Output is correct
148 Correct 3 ms 4948 KB Output is correct
149 Correct 4 ms 4948 KB Output is correct
150 Correct 4 ms 4948 KB Output is correct
151 Correct 3 ms 4948 KB Output is correct
152 Correct 3 ms 4948 KB Output is correct
153 Correct 3 ms 4948 KB Output is correct
154 Correct 3 ms 5012 KB Output is correct
155 Correct 3 ms 4948 KB Output is correct
156 Correct 3 ms 5012 KB Output is correct
157 Correct 3 ms 4948 KB Output is correct
158 Correct 3 ms 4948 KB Output is correct
159 Correct 3 ms 4948 KB Output is correct
160 Correct 3 ms 4948 KB Output is correct
161 Correct 3 ms 4948 KB Output is correct
162 Correct 3 ms 4948 KB Output is correct
163 Correct 3 ms 4948 KB Output is correct
164 Correct 3 ms 4948 KB Output is correct
165 Incorrect 4 ms 5020 KB Output isn't correct
166 Halted 0 ms 0 KB -