답안 #830964

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
830964 2023-08-19T13:51:42 Z Kerim 꿈 (IOI13_dreaming) C++17
47 / 100
72 ms 12600 KB
#include "dreaming.h"
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> pii;
const int N = 1e5+5;
vector<pii> adj[N];
vector<int> members;
bool vis[N];

void dfs0(int nd, int pr){
    vis[nd] = 1;
    members.push_back(nd);
    for (auto [to, w]: adj[nd])
        if (to != pr)
            dfs0(to, nd);
}
int max_weight, endpoint, dp[N];
void dfs(int nd, int pr, int weight){
    if (weight > max_weight){
        max_weight = weight;
        endpoint = nd;
    }
    dp[nd] = max(dp[nd], weight);
    for (auto [to, w]: adj[nd])
        if (to != pr)
            dfs(to, nd, weight+w);
}

int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
    for (int i = 0; i < m; i++){
        int u = A[i], v = B[i], w = T[i];
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }
    vector<int> roots;
    for (int i = 0; i < n; i++)
        if (!vis[i]){
            dfs0(i, -1);
            roots.push_back(i);
        }
    vector<int> w;
    int D = 0;
    for (auto root: roots){
        members.clear();
        dfs0(root, -1);

        max_weight = 0;
        dfs(root, -1, 0);
        int a = endpoint; 
        max_weight = 0;
        dfs(endpoint, -1, 0);
        int b = endpoint;
        D = max(D, max_weight);
        dfs(a, -1, 0);
        dfs(b, -1, 0);

        int value = INT_MAX;
        for (auto member: members)
            if (value > dp[member])
                value = dp[member];
        w.push_back(value);
    }
    int c = roots.size();
    int answer = D;
    if (c >= 2)
        answer = max(answer, w[0] + w[1] + L);
    if (c >= 3)
        answer = max(answer, w[0] + w[2] + 2*L);
    return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 11744 KB Output is correct
2 Correct 37 ms 11736 KB Output is correct
3 Correct 25 ms 8568 KB Output is correct
4 Correct 6 ms 4052 KB Output is correct
5 Correct 5 ms 3440 KB Output is correct
6 Correct 11 ms 4692 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 21 ms 5896 KB Output is correct
9 Correct 27 ms 7224 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 37 ms 8664 KB Output is correct
12 Correct 43 ms 10136 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2616 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2608 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 11744 KB Output is correct
2 Correct 37 ms 11736 KB Output is correct
3 Correct 25 ms 8568 KB Output is correct
4 Correct 6 ms 4052 KB Output is correct
5 Correct 5 ms 3440 KB Output is correct
6 Correct 11 ms 4692 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 21 ms 5896 KB Output is correct
9 Correct 27 ms 7224 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 37 ms 8664 KB Output is correct
12 Correct 43 ms 10136 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2616 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2608 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 1 ms 2644 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 1 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 46 ms 11732 KB Output is correct
40 Correct 37 ms 11700 KB Output is correct
41 Correct 25 ms 8580 KB Output is correct
42 Correct 6 ms 4056 KB Output is correct
43 Correct 1 ms 2644 KB Output is correct
44 Correct 1 ms 2644 KB Output is correct
45 Correct 1 ms 2644 KB Output is correct
46 Correct 1 ms 2644 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 1 ms 2644 KB Output is correct
49 Correct 1 ms 2644 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 1 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 1 ms 2644 KB Output is correct
54 Correct 1 ms 2644 KB Output is correct
55 Correct 1 ms 2644 KB Output is correct
56 Correct 1 ms 2644 KB Output is correct
57 Correct 54 ms 8796 KB Output is correct
58 Correct 51 ms 8796 KB Output is correct
59 Correct 51 ms 8716 KB Output is correct
60 Correct 52 ms 8696 KB Output is correct
61 Correct 48 ms 8648 KB Output is correct
62 Correct 48 ms 8656 KB Output is correct
63 Correct 44 ms 8388 KB Output is correct
64 Correct 53 ms 8404 KB Output is correct
65 Correct 46 ms 8460 KB Output is correct
66 Correct 47 ms 8448 KB Output is correct
67 Correct 51 ms 8596 KB Output is correct
68 Correct 51 ms 8652 KB Output is correct
69 Correct 52 ms 8644 KB Output is correct
70 Correct 53 ms 8672 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 2 ms 2772 KB Output is correct
73 Correct 2 ms 2772 KB Output is correct
74 Correct 2 ms 2772 KB Output is correct
75 Correct 2 ms 2772 KB Output is correct
76 Correct 2 ms 2772 KB Output is correct
77 Correct 3 ms 2772 KB Output is correct
78 Correct 2 ms 2772 KB Output is correct
79 Correct 2 ms 2772 KB Output is correct
80 Correct 52 ms 8620 KB Output is correct
81 Correct 53 ms 8612 KB Output is correct
82 Correct 53 ms 8644 KB Output is correct
83 Correct 47 ms 8544 KB Output is correct
84 Correct 2 ms 2772 KB Output is correct
85 Correct 2 ms 2772 KB Output is correct
86 Correct 2 ms 2772 KB Output is correct
87 Correct 2 ms 2772 KB Output is correct
88 Correct 2 ms 2772 KB Output is correct
89 Correct 3 ms 2772 KB Output is correct
90 Correct 2 ms 2772 KB Output is correct
91 Correct 2 ms 2772 KB Output is correct
92 Correct 2 ms 2772 KB Output is correct
93 Correct 2 ms 2772 KB Output is correct
94 Correct 1 ms 2644 KB Output is correct
95 Correct 1 ms 2644 KB Output is correct
96 Correct 1 ms 2644 KB Output is correct
97 Correct 2 ms 2644 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 1 ms 2644 KB Output is correct
100 Correct 1 ms 2644 KB Output is correct
101 Correct 1 ms 2644 KB Output is correct
102 Correct 1 ms 2644 KB Output is correct
103 Correct 2 ms 2644 KB Output is correct
104 Correct 6 ms 3412 KB Output is correct
105 Correct 12 ms 4656 KB Output is correct
106 Correct 1 ms 2644 KB Output is correct
107 Correct 22 ms 5908 KB Output is correct
108 Correct 27 ms 7148 KB Output is correct
109 Correct 1 ms 2644 KB Output is correct
110 Correct 40 ms 8608 KB Output is correct
111 Correct 45 ms 10060 KB Output is correct
112 Correct 2 ms 2644 KB Output is correct
113 Correct 72 ms 12600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 6624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2616 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2608 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2792 KB Output is correct
29 Incorrect 1 ms 2644 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 11744 KB Output is correct
2 Correct 37 ms 11736 KB Output is correct
3 Correct 25 ms 8568 KB Output is correct
4 Correct 6 ms 4052 KB Output is correct
5 Correct 5 ms 3440 KB Output is correct
6 Correct 11 ms 4692 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 21 ms 5896 KB Output is correct
9 Correct 27 ms 7224 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 37 ms 8664 KB Output is correct
12 Correct 43 ms 10136 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2616 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2608 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 1 ms 2644 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 1 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 46 ms 11732 KB Output is correct
40 Correct 37 ms 11700 KB Output is correct
41 Correct 25 ms 8580 KB Output is correct
42 Correct 6 ms 4056 KB Output is correct
43 Correct 1 ms 2644 KB Output is correct
44 Correct 1 ms 2644 KB Output is correct
45 Correct 1 ms 2644 KB Output is correct
46 Correct 1 ms 2644 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 1 ms 2644 KB Output is correct
49 Correct 1 ms 2644 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 1 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 1 ms 2644 KB Output is correct
54 Correct 1 ms 2644 KB Output is correct
55 Correct 1 ms 2644 KB Output is correct
56 Correct 1 ms 2644 KB Output is correct
57 Correct 54 ms 8796 KB Output is correct
58 Correct 51 ms 8796 KB Output is correct
59 Correct 51 ms 8716 KB Output is correct
60 Correct 52 ms 8696 KB Output is correct
61 Correct 48 ms 8648 KB Output is correct
62 Correct 48 ms 8656 KB Output is correct
63 Correct 44 ms 8388 KB Output is correct
64 Correct 53 ms 8404 KB Output is correct
65 Correct 46 ms 8460 KB Output is correct
66 Correct 47 ms 8448 KB Output is correct
67 Correct 51 ms 8596 KB Output is correct
68 Correct 51 ms 8652 KB Output is correct
69 Correct 52 ms 8644 KB Output is correct
70 Correct 53 ms 8672 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 2 ms 2772 KB Output is correct
73 Correct 2 ms 2772 KB Output is correct
74 Correct 2 ms 2772 KB Output is correct
75 Correct 2 ms 2772 KB Output is correct
76 Correct 2 ms 2772 KB Output is correct
77 Correct 3 ms 2772 KB Output is correct
78 Correct 2 ms 2772 KB Output is correct
79 Correct 2 ms 2772 KB Output is correct
80 Correct 52 ms 8620 KB Output is correct
81 Correct 53 ms 8612 KB Output is correct
82 Correct 53 ms 8644 KB Output is correct
83 Correct 47 ms 8544 KB Output is correct
84 Correct 2 ms 2772 KB Output is correct
85 Correct 2 ms 2772 KB Output is correct
86 Correct 2 ms 2772 KB Output is correct
87 Correct 2 ms 2772 KB Output is correct
88 Correct 2 ms 2772 KB Output is correct
89 Correct 3 ms 2772 KB Output is correct
90 Correct 2 ms 2772 KB Output is correct
91 Correct 2 ms 2772 KB Output is correct
92 Correct 2 ms 2772 KB Output is correct
93 Correct 2 ms 2772 KB Output is correct
94 Correct 1 ms 2644 KB Output is correct
95 Correct 1 ms 2644 KB Output is correct
96 Correct 1 ms 2644 KB Output is correct
97 Correct 2 ms 2644 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 1 ms 2644 KB Output is correct
100 Correct 1 ms 2644 KB Output is correct
101 Correct 1 ms 2644 KB Output is correct
102 Correct 1 ms 2644 KB Output is correct
103 Correct 2 ms 2644 KB Output is correct
104 Correct 6 ms 3412 KB Output is correct
105 Correct 12 ms 4656 KB Output is correct
106 Correct 1 ms 2644 KB Output is correct
107 Correct 22 ms 5908 KB Output is correct
108 Correct 27 ms 7148 KB Output is correct
109 Correct 1 ms 2644 KB Output is correct
110 Correct 40 ms 8608 KB Output is correct
111 Correct 45 ms 10060 KB Output is correct
112 Correct 2 ms 2644 KB Output is correct
113 Correct 72 ms 12600 KB Output is correct
114 Incorrect 17 ms 6624 KB Output isn't correct
115 Halted 0 ms 0 KB -