답안 #561117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
561117 2022-05-12T09:28:57 Z Zanite 꿈 (IOI13_dreaming) C++17
47 / 100
108 ms 24876 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[]) {
    ::N = N, ::M = M, ::L = L;

    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++;
        }
    }

	/*
	for (int i = 0; i < N; i++) {
		printf("%d: %d %d\n", i, idx[i], newLongest[i]);
	}
	*/

	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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 17868 KB Output is correct
2 Correct 64 ms 18704 KB Output is correct
3 Correct 43 ms 16132 KB Output is correct
4 Correct 13 ms 6988 KB Output is correct
5 Correct 8 ms 6288 KB Output is correct
6 Correct 17 ms 8112 KB Output is correct
7 Correct 3 ms 5012 KB Output is correct
8 Correct 29 ms 10900 KB Output is correct
9 Correct 40 ms 13824 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 66 ms 15356 KB Output is correct
12 Correct 68 ms 17176 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5012 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5012 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5012 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5012 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 4948 KB Output is correct
20 Correct 3 ms 5012 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 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 17868 KB Output is correct
2 Correct 64 ms 18704 KB Output is correct
3 Correct 43 ms 16132 KB Output is correct
4 Correct 13 ms 6988 KB Output is correct
5 Correct 8 ms 6288 KB Output is correct
6 Correct 17 ms 8112 KB Output is correct
7 Correct 3 ms 5012 KB Output is correct
8 Correct 29 ms 10900 KB Output is correct
9 Correct 40 ms 13824 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 66 ms 15356 KB Output is correct
12 Correct 68 ms 17176 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 5012 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5012 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 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 4 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 5012 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 5012 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 4948 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 5012 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 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 86 ms 19076 KB Output is correct
40 Correct 65 ms 18796 KB Output is correct
41 Correct 43 ms 16172 KB Output is correct
42 Correct 9 ms 7104 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 4948 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 3 ms 5012 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 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 3 ms 4932 KB Output is correct
57 Correct 93 ms 16220 KB Output is correct
58 Correct 108 ms 15984 KB Output is correct
59 Correct 92 ms 16268 KB Output is correct
60 Correct 97 ms 16168 KB Output is correct
61 Correct 100 ms 16588 KB Output is correct
62 Correct 106 ms 16432 KB Output is correct
63 Correct 86 ms 16332 KB Output is correct
64 Correct 94 ms 16320 KB Output is correct
65 Correct 105 ms 16704 KB Output is correct
66 Correct 87 ms 16616 KB Output is correct
67 Correct 101 ms 16276 KB Output is correct
68 Correct 100 ms 16240 KB Output is correct
69 Correct 108 ms 16436 KB Output is correct
70 Correct 90 ms 16328 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 4 ms 5340 KB Output is correct
73 Correct 4 ms 5320 KB Output is correct
74 Correct 5 ms 5332 KB Output is correct
75 Correct 4 ms 5276 KB Output is correct
76 Correct 5 ms 5320 KB Output is correct
77 Correct 4 ms 5332 KB Output is correct
78 Correct 5 ms 5284 KB Output is correct
79 Correct 6 ms 5320 KB Output is correct
80 Correct 100 ms 16160 KB Output is correct
81 Correct 88 ms 16128 KB Output is correct
82 Correct 86 ms 16504 KB Output is correct
83 Correct 97 ms 16624 KB Output is correct
84 Correct 4 ms 5204 KB Output is correct
85 Correct 4 ms 5280 KB Output is correct
86 Correct 5 ms 5204 KB Output is correct
87 Correct 4 ms 5204 KB Output is correct
88 Correct 4 ms 5280 KB Output is correct
89 Correct 5 ms 5204 KB Output is correct
90 Correct 4 ms 5204 KB Output is correct
91 Correct 4 ms 5280 KB Output is correct
92 Correct 4 ms 5332 KB Output is correct
93 Correct 5 ms 5268 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 5016 KB Output is correct
96 Correct 4 ms 4948 KB Output is correct
97 Correct 3 ms 4948 KB Output is correct
98 Correct 4 ms 5012 KB Output is correct
99 Correct 3 ms 4944 KB Output is correct
100 Correct 3 ms 4948 KB Output is correct
101 Correct 3 ms 5004 KB Output is correct
102 Correct 3 ms 4948 KB Output is correct
103 Correct 3 ms 5004 KB Output is correct
104 Correct 8 ms 6304 KB Output is correct
105 Correct 15 ms 8096 KB Output is correct
106 Correct 3 ms 4948 KB Output is correct
107 Correct 28 ms 10900 KB Output is correct
108 Correct 49 ms 13952 KB Output is correct
109 Correct 3 ms 5016 KB Output is correct
110 Correct 70 ms 15540 KB Output is correct
111 Correct 71 ms 17096 KB Output is correct
112 Correct 3 ms 5148 KB Output is correct
113 Correct 93 ms 24876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 10576 KB Output is correct
2 Correct 36 ms 10668 KB Output is correct
3 Correct 32 ms 10616 KB Output is correct
4 Correct 31 ms 10560 KB Output is correct
5 Correct 31 ms 10620 KB Output is correct
6 Correct 31 ms 11128 KB Output is correct
7 Correct 30 ms 10856 KB Output is correct
8 Correct 28 ms 10448 KB Output is correct
9 Correct 36 ms 10452 KB Output is correct
10 Correct 32 ms 10788 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 10 ms 6680 KB Output is correct
13 Correct 8 ms 6736 KB Output is correct
14 Correct 10 ms 6608 KB Output is correct
15 Correct 7 ms 6608 KB Output is correct
16 Correct 8 ms 6636 KB Output is correct
17 Correct 6 ms 6224 KB Output is correct
18 Correct 8 ms 6740 KB Output is correct
19 Correct 6 ms 6672 KB Output is correct
20 Incorrect 2 ms 4948 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5012 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5012 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5012 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5012 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 4948 KB Output is correct
20 Correct 3 ms 5012 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 4948 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 5204 KB Output is correct
28 Correct 4 ms 5332 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 5 ms 5300 KB Output is correct
31 Correct 6 ms 5312 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 4 ms 5204 KB Output is correct
34 Correct 4 ms 5280 KB Output is correct
35 Correct 4 ms 5012 KB Output is correct
36 Correct 3 ms 5012 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 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 5024 KB Output is correct
44 Correct 3 ms 4948 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 5008 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 5008 KB Output is correct
52 Incorrect 3 ms 4948 KB Output isn't correct
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 17868 KB Output is correct
2 Correct 64 ms 18704 KB Output is correct
3 Correct 43 ms 16132 KB Output is correct
4 Correct 13 ms 6988 KB Output is correct
5 Correct 8 ms 6288 KB Output is correct
6 Correct 17 ms 8112 KB Output is correct
7 Correct 3 ms 5012 KB Output is correct
8 Correct 29 ms 10900 KB Output is correct
9 Correct 40 ms 13824 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 66 ms 15356 KB Output is correct
12 Correct 68 ms 17176 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 5012 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5012 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 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 4 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 5012 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 5012 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 4948 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 5012 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 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 86 ms 19076 KB Output is correct
40 Correct 65 ms 18796 KB Output is correct
41 Correct 43 ms 16172 KB Output is correct
42 Correct 9 ms 7104 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 4948 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 3 ms 5012 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 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 3 ms 4932 KB Output is correct
57 Correct 93 ms 16220 KB Output is correct
58 Correct 108 ms 15984 KB Output is correct
59 Correct 92 ms 16268 KB Output is correct
60 Correct 97 ms 16168 KB Output is correct
61 Correct 100 ms 16588 KB Output is correct
62 Correct 106 ms 16432 KB Output is correct
63 Correct 86 ms 16332 KB Output is correct
64 Correct 94 ms 16320 KB Output is correct
65 Correct 105 ms 16704 KB Output is correct
66 Correct 87 ms 16616 KB Output is correct
67 Correct 101 ms 16276 KB Output is correct
68 Correct 100 ms 16240 KB Output is correct
69 Correct 108 ms 16436 KB Output is correct
70 Correct 90 ms 16328 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 4 ms 5340 KB Output is correct
73 Correct 4 ms 5320 KB Output is correct
74 Correct 5 ms 5332 KB Output is correct
75 Correct 4 ms 5276 KB Output is correct
76 Correct 5 ms 5320 KB Output is correct
77 Correct 4 ms 5332 KB Output is correct
78 Correct 5 ms 5284 KB Output is correct
79 Correct 6 ms 5320 KB Output is correct
80 Correct 100 ms 16160 KB Output is correct
81 Correct 88 ms 16128 KB Output is correct
82 Correct 86 ms 16504 KB Output is correct
83 Correct 97 ms 16624 KB Output is correct
84 Correct 4 ms 5204 KB Output is correct
85 Correct 4 ms 5280 KB Output is correct
86 Correct 5 ms 5204 KB Output is correct
87 Correct 4 ms 5204 KB Output is correct
88 Correct 4 ms 5280 KB Output is correct
89 Correct 5 ms 5204 KB Output is correct
90 Correct 4 ms 5204 KB Output is correct
91 Correct 4 ms 5280 KB Output is correct
92 Correct 4 ms 5332 KB Output is correct
93 Correct 5 ms 5268 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 5016 KB Output is correct
96 Correct 4 ms 4948 KB Output is correct
97 Correct 3 ms 4948 KB Output is correct
98 Correct 4 ms 5012 KB Output is correct
99 Correct 3 ms 4944 KB Output is correct
100 Correct 3 ms 4948 KB Output is correct
101 Correct 3 ms 5004 KB Output is correct
102 Correct 3 ms 4948 KB Output is correct
103 Correct 3 ms 5004 KB Output is correct
104 Correct 8 ms 6304 KB Output is correct
105 Correct 15 ms 8096 KB Output is correct
106 Correct 3 ms 4948 KB Output is correct
107 Correct 28 ms 10900 KB Output is correct
108 Correct 49 ms 13952 KB Output is correct
109 Correct 3 ms 5016 KB Output is correct
110 Correct 70 ms 15540 KB Output is correct
111 Correct 71 ms 17096 KB Output is correct
112 Correct 3 ms 5148 KB Output is correct
113 Correct 93 ms 24876 KB Output is correct
114 Correct 29 ms 10576 KB Output is correct
115 Correct 36 ms 10668 KB Output is correct
116 Correct 32 ms 10616 KB Output is correct
117 Correct 31 ms 10560 KB Output is correct
118 Correct 31 ms 10620 KB Output is correct
119 Correct 31 ms 11128 KB Output is correct
120 Correct 30 ms 10856 KB Output is correct
121 Correct 28 ms 10448 KB Output is correct
122 Correct 36 ms 10452 KB Output is correct
123 Correct 32 ms 10788 KB Output is correct
124 Correct 2 ms 4948 KB Output is correct
125 Correct 10 ms 6680 KB Output is correct
126 Correct 8 ms 6736 KB Output is correct
127 Correct 10 ms 6608 KB Output is correct
128 Correct 7 ms 6608 KB Output is correct
129 Correct 8 ms 6636 KB Output is correct
130 Correct 6 ms 6224 KB Output is correct
131 Correct 8 ms 6740 KB Output is correct
132 Correct 6 ms 6672 KB Output is correct
133 Incorrect 2 ms 4948 KB Output isn't correct
134 Halted 0 ms 0 KB -